Re: [R] subset by two variables

From: Marc Schwartz (via MN) <>
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 mailing list PLEASE do read the posting guide 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 Please read the posting guide before posting to the list.