Skip to content
Prev 17973 / 20628 Next

[FORGED] Re: Export several lme outputs to a single excel file

On 8/10/19 9:28 PM, Mario Garrido wrote:

            
This is a "generic" problem; it is not peculiar to your model nor to 
models fitted using lme, or other mixed modelling software.

Consider the following example:

set.seed(42)
x <- 1:20
y <- rnorm(20)
fit <- lm(y ~ x)
m   <- anova(fit)
m$newColumn <- "yeeeeks"
m

This produces:
The "reason" is that m is (in the first instance) of class "anova" and 
there are (not unreasonably) certain restrictions as to how you can 
treat an object of this class.

A work-around to get something like what you appear to want could be:

set.seed(42)
x <- 1:20
y <- rnorm(20)
fit <- lm(y ~ x)
m   <- anova(fit)
m   <- cbind(m,newColumn=c("yeeeks",rep("",nrow(m)-1)))
m

However m is now of class "data.frame" whence it is printed by the 
method print.data.frame() rather than print.anova().  Consequently NAs 
show up in the output of the print method:

           Df      Sum Sq    Mean Sq    F value    Pr(>F) newColumn
x          1  0.04176282 0.04176282 0.03784897 0.8479256    yeeeks
Residuals 18 19.86132473 1.10340693         NA        NA

You could just live with those NAs, or you could convert the "F value" 
and "Pr(>F)" columns from numeric to character mode and replace the NAs 
by null strings "".

HTH

cheers,

Rolf Turner