[R] subset
Vaidotas Zemlys
mpiktas at delfi.lt
Fri Sep 13 10:31:17 CEST 2002
Hi,
> I have a simple question. If I need to run linear regression on a subset of
> the dataset, will
> the following two commands give the same output:
>
> lm(y ~ as.factor(x1) + as.factor(x2), data, subset = z==Z[1])
>
> and
>
> lm(y ~ as.factor(x1) + as.factor(x2), data[data$z==Z[1],] )
>
>
> I have got different results running the two commands. Am I missing
> something here, or it
> there a bug on the option subset?
>
I tried the same thing at my computer and everything works fine. Maybe
you have variable z, which is not the same as in your data frame. That is
data$z!=z,
Try do something like
zz_z
rm(z)
and then repeat your two lm calls. Then I think the results should be
the same.
Vaidotas Zemlys
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list