[R] convert to binary to decimal

Martin Feldkircher feldkirc at ihs.ac.at
Thu Feb 15 16:38:15 CET 2007


Hello,
we need to convert a logical vector to a (decimal) integer. Example:

a=c(TRUE, FALSE, TRUE) (binary number 101)

the function we are looking for should return

dec2bin(a)=5

Is there a package for such a function or is it even implemented in the 
base package? We found the hexmode and octmode command, but not a 
binmode. We know how to program it ourselves however we are looking for 
a computationally efficient algorithm.

Martin and Stefan



More information about the R-help mailing list