[R] split number into array
arun
smartpink111 at yahoo.com
Thu Apr 25 14:35:58 CEST 2013
Hi,Not sure about the criteria for deciding number of zeros.
vec1<- c(23,244,1343,45,153555,5468999999,75)
lst1<- strsplit(as.character(vec1),"")
m1<-max(sapply(lst1,length))
res<- t(sapply(lst1,function(x) as.numeric(c(rep(0,m1-length(x)),x))))
res
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#[1,] 0 0 0 0 0 0 0 0 2 3
#[2,] 0 0 0 0 0 0 0 2 4 4
#[3,] 0 0 0 0 0 0 1 3 4 3
#[4,] 0 0 0 0 0 0 0 0 4 5
#[5,] 0 0 0 0 1 5 3 5 5 5
#[6,] 5 4 6 8 9 9 9 9 9 9
#[7,] 0 0 0 0 0 0 0 0 7 5
A.K.
>hi, I'm a new R user.
>I have a for cycle which generates number from 0 to N, and i wanna put this number into an array:
>
>i.e. number 23 into an array of int: a(0,0,0,0,2,3)
>
>can you help me?
>Federico
More information about the R-help
mailing list