Re: [R] how to store a number into a vector

2011-01-23 Thread David Winsemius
On Jan 23, 2011, at 6:00 PM, Thomas Stewart wrote: Here is a hack, crude solution to get the digits: Digits <- function(a){ out <- rep(NA,nchar(a)) for(i in 1:nchar(a)) out[i] <- substr(a,i,i) return(as.numeric(out)) } Digits(183429) str1 <- c(12345, 34567, 45678) sapply(strsplit(as.charact

Re: [R] how to store a number into a vector

2011-01-23 Thread David Winsemius
On Jan 23, 2011, at 6:00 PM, Thomas Stewart wrote: Here is a hack, crude solution to get the digits: Digits <- function(a){ out <- rep(NA,nchar(a)) for(i in 1:nchar(a)) out[i] <- substr(a,i,i) return(as.numeric(out)) } Digits(183429) str1 <- c(12345, 34567, 45678) sapply(strsplit(as.char

Re: [R] how to store a number into a vector

2011-01-23 Thread Thomas Stewart
Here is a hack, crude solution to get the digits: Digits <- function(a){ out <- rep(NA,nchar(a)) for(i in 1:nchar(a)) out[i] <- substr(a,i,i) return(as.numeric(out)) } Digits(183429) If all you want is the last three numbers, consider another hack solution: Last3Digits <- function(a) a

Re: [R] how to store a number into a vector

2011-01-23 Thread jim holtman
Do you want to store each digit as a separate character, or if you want to compare the last three digits with other numbers, then use the "%%" operator. > x <- 12345 > x %% 1000 [1] 345 On Sun, Jan 23, 2011 at 1:39 PM, Quan Zhou wrote: > Hi Everyone, > A quick question how to store a number lik

Re: [R] how to store a number into a vector

2011-01-23 Thread David Winsemius
On Jan 23, 2011, at 1:39 PM, Quan Zhou wrote: Hi Everyone, A quick question how to store a number like 12345 to a vector or array with size(1,5), like 1, 2, 3, 4, 5 ?strsplit ?unlist So I can compare if the last three digits of this number is the same with some other numbers. Davi