Re: [R] String question

2006-11-29 Thread Romain Francois
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

Re: [R] String question

2006-11-29 Thread John Fox
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

Re: [R] String question

2006-11-29 Thread Petr Pikal
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

Re: [R] String question

2006-11-29 Thread Gabor Grothendieck
Try: # TRUE if all 0 and 1 regexpr(^[01]*$, bits) 0 # positions of 1s gregexpr(1, bits)[[1]] On 11/29/06, Carmen Meier [EMAIL PROTECTED] 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