[R] means over factors in mlm terms
Gabor Grothendieck
ggrothendieck at gmail.com
Tue Nov 21 17:47:19 CET 2006
On 11/21/06, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> I am not sure I understand the question -- is it how to get the same
> result you did but without warnings? The warnings are, of course,
> there since you are trying to take means of factors and its not clear
> what that really is supposed to do.
>
> At any rate you could eliminate the factors and then take the means
> of what is left or you could convert the factors to numeric if that makes
> any sense. Here are a few alternatives using aggregate and
> summaryBy from the doBy package
>
>
> aggregate(data.matrix(soils), soils["Contour"], mean)
>
> # same but removing factors
> aggregate(data.matrix(soils[,-(2:4)]), soils["Contour"], mean)
>
> library(doBy)
> summaryBy(. ~ Contour, soils, keep.names = TRUE)
>
> # same but removing factors
> summaryBy(.~ Contour, soils[,-(3:4)], keep.names = TRUE)
Hmm. It seems summaryBy automatically removes the factors from
the left hand side so the last two are actually the same.
More information about the R-help
mailing list