[R] String question

Romain Francois rfrancois at mango-solutions.com
Wed Nov 29 15:16:57 CET 2006


Carmen Meier wrote:
> Hi to all
> I would to determinate whether bits is a binary code and I would to find 
> out the which bit is set to 1
>
> bits <-"00110110"
> I found to detect whether there are only numbers
> all.digits(bits)
> but is there any function to detect whether there are only 0 and 1 in 
> the string
>
> And how could I get the f.e the third "bit" from the right hand side
>
> With regards Carmen
>   
Hi,

R> nc <- nchar(bits)
R> substring(bits,1:nc,1:nc) == "1"
R> which( substring(bits,1:nc,1:nc) == "1"  )


Cheers,

Romain

-- 
Mango Solutions
Tel  +44 1249 467 467
Fax  +44 1249 467 468
Mob  +44 7813 526 123
data analysis that delivers



More information about the R-help mailing list