Re: [R] using subset() in data frame

From: Robert Walters <>
Date: Sat, 23 Feb 2008 09:13:56 -0500

Chuck Cleland wrote:
> On 2/23/2008 6:09 AM, Chuck Cleland wrote: >> On 2/22/2008 8:01 PM, Robert Walters wrote:

Thanks for the pointers on subset(). When I submit the two variants you suggested, below:

> fit1 <- lm(y ~ x, subset(data.b, porosity == "macro"))
Error in eval(expr, envir, enclos) : object "porosity" not found

> fit1 <- lm(pore.pct ~ Db, data.b[data.b$porosity=="macro",])
Error in, y, ...) :

   0 (non-NA) cases

So, the problem is there are no objects defined for data.b, as confirmed by the following query:

> objects()

[1] "data.a" "data.a0" "data.b"

> objects(data.b)

Error in as.environment(pos) : invalid object for 'as.environment'

However, when I submit the following queries:
> names(data.b)

[1] "system" "block" "position" ...

> levels(data.b$porosity)

[1] "macro " "micro"

> print(data.b$porosity)

  [1] macro...
[26] micro...
[51] macro...
[76] micro...

R returns values in each instance. Therein lies my confusion. Furthermore,I can plot data.b with xyplot(), a very nice coplot is produced.

Any thoughts?

Robert mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Sat 23 Feb 2008 - 14:26:43 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 Sat 23 Feb 2008 - 18:30:16 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive