[R] String question

Petr Pikal petr.pikal at precheza.cz
Wed Nov 29 15:28:27 CET 2006


Hi

gregexpr can be used

bits <-"0011011aaa0"
gregexpr("[01]", bits)
[[1]]
[1]  1  2  3  4  5  6  7 11
attr(,"match.length")
[1] 1 1 1 1 1 1 1 1

or

grep("[^01]", bits)
if you want to know that there is any other character then 0 or 1

gregexpr("1", bits)
if you want to know location of 1's

HTH
Petr

On 29 Nov 2006 at 15:06, Carmen Meier wrote:

Date sent:      	Wed, 29 Nov 2006 15:06:08 +0100
From:           	Carmen Meier <carmei3 at web.de>
To:             	R-help <r-help at stat.math.ethz.ch>
Subject:        	[R] String question

> 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
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.

Petr Pikal
petr.pikal at precheza.cz



More information about the R-help mailing list