[R] String question
John Fox
jfox at mcmaster.ca
Wed Nov 29 15:24:52 CET 2006
Dear Carmen,
length(grep("[^01]", bits)) == 0
should do the trick, returning TRUE if the string contains only 0's and 1's.
I hope this helps,
John
--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox
--------------------------------
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Carmen Meier
> Sent: Wednesday, November 29, 2006 9:06 AM
> To: R-help
> 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.
More information about the R-help
mailing list