I'm having trouble exporting my TukeyHSD results so that they are separated in cells when I open the results up in something like Excel. I tried using write.csv() but it says:
cannot coerce class "c("TukeyHSD", "multicomp")" to a data.frame
How can I capture my TukeyUSD results in a way that I can just copy and paste them into an Excel sheet?
TukeyHSD
returns a an object of class "TukeyHSD". You can extract the table of results from the "TukeyHSD" object using the $
operator. You can then export or modify the table in any way you see fit.
fm1 <- aov(breaks ~ wool + tension, data = warpbreaks)
res <- TukeyHSD(fm1, "tension", ordered = TRUE)
as.data.frame(res$tension)
# diff lwr upr p adj
# M-H 4.722222 -4.6311985 14.07564 0.447421021
# L-H 14.722222 5.3688015 24.07564 0.001121788
# L-M 10.000000 0.6465793 19.35342 0.033626219