Look carefully at the output and commands below.
 
The first level of porosity is "macro " (notice the space at the end) but you are asking for "macro" (without the space).  Computers are very literal, so "macro " is not equal to "macro".  Try it again with the space (or renaming the level in the factor to not include the space).  Also check to see if the name of porosity has a space or something in it (the $ method will do a partial match so data.b$porosity will match if the factor is named "porosity" or "porosity " or "porosity.somethingelseafterthemainname", but the subset command is only looking for something named "porosity" and will not match the others).
 
Hope this helps, 

________________________________

From: r-help-bounces@r-project.org on behalf of Robert Walters
Sent: Sat 2/23/2008 7:13 AM
To: Chuck Cleland
Cc: r-help@r-project.org
Subject: Re: [R] using subset() in data frame



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

Chuck,
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 lm.fit(x, 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

______________________________________________
R-help@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.



	[[alternative HTML version deleted]]

