Skip to content
Prev 298991 / 398506 Next

Removing rows if certain elements are found in character string

Hello,

Inline.

Em 03-07-2012 01:15, jim holtman escreveu:
Right, apparently, I forgot that grep is greedy, and the test cases were 
not complete.
This is only for the first request, and does not solve cases where there 
are characters other than '0', 'd' or 'D', but 'd' or 'D' are the first 
non-zero. This is the case of my 4th row, changed from the OP's data 
example.

My regexpr for 'i2' is equivalent to this one, that I believe is more 
readable:


i2b <- grepl("^0{0,}[Dd]", dd$ch)


First a zero, that might occur zero or more times, then a 'd' or 'D', 
then and til the end, irrelevant.
To the OP: bottom line, use Jim's 'i1new' and my 'i2' or 'i2b'.

Rui Barradas