[R] How to filter a data frame?

Marc Schwartz marc_schwartz at comcast.net
Tue Jul 22 16:07:31 CEST 2008


on 07/22/2008 08:47 AM rlearner309 wrote:
> I have a question about how to filter the data frame:
> Suppose my data frame has variables like gender, age,... How to get a subset
> of the data frame, with only female (or male) and/or age > 50...?  What is
> the typical syntax?  I tried several condition expressions, but none of them
> worked...
> 
> Thanks a lot!


See ?subset and ?Logic

For example:

   DF.new <- subset(DF, (gender == "female") & (age > 50))

HTH,

Marc Schwartz



More information about the R-help mailing list