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
This one worked for me
ANOVA_Tc<-aov(Concentration~ Sample, data= Tc)
summary(ANOVA_Tc)
TKHSD_Tc <- TukeyHSD(ANOVA_Tc)
TK<-(TKHSD_Tc)
TK_data<-as.data.frame(TK[1]) # the [1] locates the part of the output to be exported
write.csv(TK_data, 'TK_data.csv')
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