[R] logical operators in 'subset'

From: Reitsma, Rene - COB <reitsmar_at_bus.oregonstate.edu>
Date: Thu, 13 Nov 2008 10:38:45 -0800


Dear All,

Am I correct in believing that logical operators such as && and || cannot be used as part of
a 'subset' logical expression?

Example:

>foo = as.data.frame(matrix(c(1:9), nrow=3, ncol=3,
dimnames=list(c("r1","r2","r3"),c("c1","c2","c3"))))

>foo

   c1 c2 c3
r1 1 4 7
r2 2 5 8
r3 3 6 9

>subset(foo, c1 > 1)

   c1 c2 c3
r2 2 5 8
r3 3 6 9

>subset(foo, c2 > 5)

   c1 c2 c3
r3 3 6 9

However,

>subset(foo, c1 > 1 && c2 > 5)

[1] c1 c2 c3
<0 rows> (or 0-length row.names)

RR



R-help_at_r-project.org 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 Thu 13 Nov 2008 - 18:41:22 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 13 Nov 2008 - 19:31:23 GMT.

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

list of date sections of archive