Happy weekend helpeRs!

As usual, I'm stumped by R...

My plan was to take an integer number, convert it to binary and wind
up with a data.frame where each column is either 1 or 0 so I can see
which bits are changing:

bb<-function(i) ifelse(i, paste(bb(i %/% 2), i %% 2, sep=""), "")
my.dat<-c(36,40,10,4)
my.binary.dat<-bb(my.dat)
my.list<-strsplit(my.binary.dat,'')

max.len<-max(ldply(my.list,length))
len<-length(my.list)
my.df<-data.frame(two=rep(0,len),four=rep(0,len),eight=rep(0,len),sixteen=rep(0,len),thirtytwo=rep(0,len),sixtyfour=rep(0,len))
for(i in 1:length(my.list)){
        for(j in 1:length(my.list[[i]])){
                my.df[i,max.len-length(my.list[[i]])+j]<-my.list[[i]][j]        
        }
}

But this isn't exactly feasable on a million+ rows where some binary
numbers are 20 digits...  I know theres a way without loops I just
know it!

Ideally, I can do this to multiple columns of a data.frame and have
them named accordingly (V1.two,V1.four... V2.two,V2.four, etc.)


Thanks,

Justin

______________________________________________
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.

Reply via email to