extract the digits of a number
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 1 On Tue, Dec 9, 2008 at 12:48 PM, Gustavo Carvalho
<gustavo.bio+R at gmail.com> wrote:
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 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.