I wonder how to extract emmean
and SE
columns from emmGrid
of emmeans
R
package. MWE is given below.
library(emmeans)
warp.lm <- lm(breaks ~ wool * tension, data = warpbreaks)
Test <- emmeans(warp.lm, specs = "wool")
Test
wool emmean SE df lower.CL upper.CL
A 31.03704 2.105459 48 26.80373 35.27035
B 25.25926 2.105459 48 21.02595 29.49257
Results are averaged over the levels of: tension
Confidence level used: 0.95
class(Test)
[1] "emmGrid"
attr(,"package")
[1] "emmeans"
summary(Test)
gives a data.frame instead.
class(summary(Test))
[1] "summary_emm" "data.frame"
So one can do:
summary(Test)$emmean
[1] 31.03704 25.25926
And
summary(Test)$SE
[1] 2.105459 2.105459
To actually get a new subsetted data.frame, you need to explicitly coerce to class data.frame:
as.data.frame(summary(Test))[c('emmean', 'SE')]
emmean SE 1 31.03704 2.105459 2 25.25926 2.105459
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With