Skip to content
Prev 299220 / 398521 Next

Removing rows if certain elements are found in character string

Perhaps I've missed something, but if it's really true that the goal is to
remove rows if the first non-zero element is "D" or "d", then how about
this:

tmp <- gsub('0','',df$ch)
first <- substr(tmp,1,1)
subset(df, tolower(first) != 'd')

and of course it could be rolled up into a single expression, but I wrote
it in several steps to make it easy to follow. No need to wrap one's brain
around regular expressions (which is hard for me!)

-Don