Re: [R] subset by two variables

From: Marc Schwartz (via MN) <mschwartz_at_mn.rr.com>
Date: Wed 30 Aug 2006 - 06:20:25 EST

On Tue, 2006-08-29 at 13:05 -0700, Dean Sonneborn wrote:
> I'm using this syntax to create data subsets for plots:
> subset=source=="Both". Now I would like to create a subset defined by
> two different variables like this: subset=source=="Both"
> subset=site=="home" but this syntax is not correct. The documents in the
> manual for subset seem to be creating whole new data files not just
> selecting rows based on the contents of the variables. How do I subset
> based on two variables.

If your data frame is called 'DF':

  plot(y ~ x, data = DF, subset = (source == "Both") & (site == "home"))

See ?Logic and ?Syntax for more information on creating logical expressions.

HTH, Marc Schwartz



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed Aug 30 06:23:25 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 30 Aug 2006 - 08:23:33 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.