I have a huge number such as 78923698701 z<-78923698701 I want to find the integer of a given location, for example here, what is the 2nd number? 8. Thanks in advance! -- View this message in context: http://www.nabble.com/the-integer-of-a-given-location-tp25418729p25418729.html Sent from the R help mailing list archive at Nabble.com.
Is this what you want:> z<-78923698701 > substring(as.character(z), 2, 2)[1] "8">On Sat, Sep 12, 2009 at 6:16 PM, darkhorn <darkhorn at gmail.com> wrote:> > I have a huge number such as 78923698701 > z<-78923698701 > I want to find the integer of a given location, for example here, what is > the 2nd number? 8. > > Thanks in advance! > -- > View this message in context: http://www.nabble.com/the-integer-of-a-given-location-tp25418729p25418729.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Hi darkhorn, Here are two suggestions: # Suggestion 1 z <- 78923698701 foo <- function(x, pos) strsplit(as.character(x),"")[[1]][pos] foo(z,2) # [1] "8" # Suggestion 2 foo2 <- function(x, pos) substr(x,pos,pos) foo2(z,2) # [1] "8" See ?strsplit and ?substr for more details. HTH, Jorge On Sat, Sep 12, 2009 at 6:16 PM, darkhorn <darkhorn@gmail.com> wrote:> > I have a huge number such as 78923698701 > z<-78923698701 > I want to find the integer of a given location, for example here, what is > the 2nd number? 8. > > Thanks in advance! > -- > View this message in context: > http://www.nabble.com/the-integer-of-a-given-location-tp25418729p25418729.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Thank you very much. :-)> as.integer(substring(as.character(z), 2, 2))[1] 8> as.integer(foo2(z,2))[1] 8 -- View this message in context: http://www.nabble.com/the-integer-of-a-given-location-tp25418729p25419555.html Sent from the R help mailing list archive at Nabble.com.