[R] How to subset() from data frame using specific rows

Rich Shepard rshepard at appl-ecosys.com
Tue Oct 4 21:07:10 CEST 2011

On Tue, 4 Oct 2011, R. Michael Weylandt wrote:

> This isn't going to be the most elegant, but it should work:
> ## Get the factors as characters
> ff <- as.character(chemdata$site)
>> ## Identify those that match what you want
> ff <- grepl(ff, "BC-")


   Apparently grep works differently in R than it does on the command line:

bf <- grep(ff, "BC-")
Warning message:
In grep(ff, "BC-") :
   argument 'pattern' has length > 1 and only the first element will be used

   I understand what you suggest but it does not appear to work for me.



More information about the R-help mailing list