R语言 将TukeyHSD比较(第一列)分离到新的数据框中,将一列拆分为两列

xsuvu9jc  于 2023-01-10  发布在  其他
关注(0)|答案(1)|浏览(164)

我正在对一些数据进行双因素方差分析。当进行TukeyHSD事后分析时,给出了以下输出:

diff        lwr       upr     p adj
0.1-0          -7.6925867  -79.28269  63.89752 0.9999650
1-0             9.6882972  -40.93355  60.31014 0.9984060
10-0            4.1546350  -46.46721  54.77648 0.9999945
100-0           7.4767801  -44.70303  59.65659 0.9997580
1000-0          7.9958523  -41.34422  57.33593 0.9994555
10000-0        11.6970426  -42.41999  65.81407 0.9965756
100000-0     -104.3276885 -158.44472 -50.21066 0.0000106
1-0.1          17.3808839  -54.20922  88.97099 0.9930363
10-0.1         11.8472217  -59.74288  83.43732 0.9993756
100-0.1        15.1693668  -57.53073  87.86946 0.9972505
1000-0.1       15.6884389  -55.00112  86.37800 0.9959677
10000-0.1      19.3896293  -54.71317  93.49243 0.9891406
100000-0.1    -96.6351019 -170.73790 -22.53230 0.0038992
10-1           -5.5336622  -56.15551  45.08819 0.9999607
100-1          -2.2115171  -54.39132  49.96829 0.9999999
1000-1         -1.6924450  -51.03252  47.64763 1.0000000
10000-1         2.0087454  -52.10829  56.12578 1.0000000
100000-1     -114.0159857 -168.13302 -59.89895 0.0000019
100-10          3.3221451  -48.85766  55.50195 0.9999990
1000-10         3.8412172  -45.49886  53.18129 0.9999962
10000-10        7.5424076  -46.57462  61.65944 0.9997987
100000-10    -108.4823236 -162.59935 -54.36529 0.0000051
1000-100        0.5190721  -50.41818  51.45632 1.0000000
10000-100       4.2202625  -51.35684  59.79736 0.9999968
100000-100   -111.8044686 -167.38157 -56.22737 0.0000047
10000-1000      3.7011904  -49.21879  56.62117 0.9999982
100000-1000  -112.3235408 -165.24352 -59.40356 0.0000016
100000-10000 -116.0247312 -173.42451 -58.62495 0.0000043

是否有简单的方法将第一列分离到新数据框中(这将是ggplot中p_stat_manual的数据输入,它要求数据框为Group 1|第二组|(p))
即第1列,第1行表示:0.1-0。在新 Dataframe 中,如何在列Group1中设置0.1,在列Group2中设置0,等等......
目前,我正在手写以下内容,但这很耗时,而且容易引入错误:

group1 <- (c(1, 10, 100, 1000, 10000, 100000, "DMSO", 10, 100, 1000, 10000, 100000, "DMSO", 100, 1000, 10000, 100000, "DMSO", 1000, 10000, 100000, "DMSO", 10000, 100000, "DMSO", 100000, "DMSO", "DMSO"))
 
group2 <- factor(c(0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 100, 100, 100, 100, 1000, 1000,1000, 10000, 10000, 100000))
ulydmbyx

ulydmbyx1#

下面是一个如何实现的示例,我使用了?TukeyHSD示例。

library(dplyr)
library(tibble)
library(tidyr)

fm1 <- aov(breaks ~ wool + tension, data = warpbreaks)

tukey <- TukeyHSD(fm1, "tension", ordered = TRUE)

tukey$tension %>% 
  as.data.frame() %>% 
  rownames_to_column() %>% 
  separate(col = rowname,into = c("var1","var2"))

相关问题