Re: [R] extract the digits of a number

2008-12-09 Thread Gabor Grothendieck
Actually what you have is not so bad. Here is a variation which has one fewer nested (...) > as.numeric(strsplit(as.character(mynumber),"")[[1]]) [1] 1 0 0 1 > # or > # Try strapply in gsubfn: > library(gsubfn) > mynmber <- 1001 > strapply(as.character(mynumber), ".", as.numeric)[[1]] [1] 1 0 0

Re: [R] extract the digits of a number

2008-12-09 Thread Greg Snow
org] On Behalf Of Gustavo Carvalho > Sent: Tuesday, December 09, 2008 10:49 AM > To: r-help@r-project.org > Subject: [R] extract the digits of a number > > Hello, > > Anyone knows how can I do this in a cleaner way? > > mynumber = 1001 > as.numeric(unlist(strsplit(as.cha

Re: [R] extract the digits of a number

2008-12-09 Thread Henrique Dallazuanna
Try this also: library(gsubfn) strapply(as.character(mynumber), "[0-9]", simplify = as.numeric) On Tue, Dec 9, 2008 at 3:48 PM, Gustavo Carvalho <[EMAIL PROTECTED]<[EMAIL PROTECTED]> > wrote: > Hello, > > Anyone knows how can I do this in a cleaner way? > > mynumber = 1001 > as.numeric(unlist(st

Re: [R] extract the digits of a number

2008-12-09 Thread Christos Hatzis
ilto:[EMAIL PROTECTED] On Behalf Of Gustavo Carvalho > Sent: Tuesday, December 09, 2008 12:49 PM > To: r-help@r-project.org > Subject: [R] extract the digits of a number > > Hello, > > Anyone knows how can I do this in a cleaner way? > > mynumber = 1001 > as.numeric

[R] extract the digits of a number

2008-12-09 Thread Gustavo Carvalho
Hello, Anyone knows how can I do this in a cleaner way? mynumber = 1001 as.numeric(unlist(strsplit(as.character(mynumber),""))) [1] 1 0 0 1 Thanks in advance, Gustavo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help P