Re: [R] Convert bits to numbers in base 10

2009-04-09 Thread Gang Chen
Yes, such a concise and elegant solution! Thanks a lot! Gang On Thu, Apr 9, 2009 at 5:51 PM, Marc Schwartz wrote: > I suspect that Gang was looking for something along the lines of: > >> sum(2 ^ (which(as.logical(rev(nn))) - 1)) > [1] 74 > > You might also want to look at the digitsBase() funct

Re: [R] Convert bits to numbers in base 10

2009-04-09 Thread Michael Conklin
ez Cc: R-help; Gang Chen Subject: Re: [R] Convert bits to numbers in base 10 I suspect that Gang was looking for something along the lines of: > sum(2 ^ (which(as.logical(rev(nn))) - 1)) [1] 74 You might also want to look at the digitsBase() function in Martin's sfsmisc package on CRAN.

Re: [R] Convert bits to numbers in base 10

2009-04-09 Thread Marc Schwartz
I suspect that Gang was looking for something along the lines of: > sum(2 ^ (which(as.logical(rev(nn))) - 1)) [1] 74 You might also want to look at the digitsBase() function in Martin's sfsmisc package on CRAN. HTH, Marc Schwartz On Apr 9, 2009, at 4:34 PM, Jorge Ivan Velez wrote: Dear G

Re: [R] Convert bits to numbers in base 10

2009-04-09 Thread Jorge Ivan Velez
Dear Gang, Try this: nn <- c(1, 0, 0, 1, 0, 1,0) paste(nn,sep="",collapse="") See ?paste for more information. HTH, Jorge On Thu, Apr 9, 2009 at 5:23 PM, Gang Chen wrote: > I have some bits stored like the following variable nn > > (nn <- c(1, 0, 0, 1, 0, 1,0)) > [1] 1 0 0 1 0 1 0 > > not i

[R] Convert bits to numbers in base 10

2009-04-09 Thread Gang Chen
I have some bits stored like the following variable nn (nn <- c(1, 0, 0, 1, 0, 1,0)) [1] 1 0 0 1 0 1 0 not in the format of 1001010 and I need to convert them to numbers in base 10. What's an easy way to do it? TIA, Gang __ R-help@r-project.org mail