Exporting TukeyHSD results
Asked Answered
W

2

5

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?

Witenagemot answered 25/7, 2016 at 15:27 Comment(3)
Can you please edit to make this a reproducible question? I think it's fantastic that you are participating in the SO community, you need to take a little time to learn how to be a good SO citizen. This is arguably the third non-reproducible question you have posted in a week. Also, if people provide an answer that solves your problem, please take the time to click the check box next to their answer (accepting the answer).Carolinian
I'll be happy to remove the down-vote once you edit the question. See in my answer how I provided a complete example to make the code run and illustrate problem. Often, if you're looking for a quick example you can go to the help file for that function. In this case I lifted the example from ?TukeyHSD.Carolinian
I figured it out but I will be sure to follow your advice for next time that I need help. Thank you!Witenagemot
C
10

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
Carolinian answered 25/7, 2016 at 15:34 Comment(0)
T
8

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')
Tingey answered 5/1, 2018 at 8:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.