Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting TukeyHSD results

Tags:

r

export

tukey

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?

like image 358
Ren Zhang Avatar asked Dec 10 '22 15:12

Ren Zhang


2 Answers

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
like image 103
dayne Avatar answered Jan 09 '23 07:01

dayne


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')
like image 26
Shakes Avatar answered Jan 09 '23 09:01

Shakes