在 R 中编制索引时出现"Incorrect number of dimensions"错误



我第二次分析论文的一些结果,因为我有了新的数据,我使用了dunntest((函数,得到了一个这样的表:

Comparison          Z      P.unadj        P.adj
1  D20FN30K - D20FN60K -1.7340246 8.291372e-02 1.160792e-01
2  D20FN30K - D20MG30K  1.3602563 1.737488e-01 2.211349e-01
3  D20FN60K - D20MG30K  3.0942809 1.972906e-03 3.068965e-03

然而,当我试图通过键入PT[,4]将其索引为只有p值时,它会给我一个错误,说";尺寸数目不正确";。我使用的代码和我第一次使用的代码一样,当时它有效,但现在突然不起作用了。

我试图使用FSA包中的dunntest函数执行dunntest,但据我所说,问题是您的函数输出不是数据帧或矩阵。

您需要从输出中提取结果数据帧

以下是为测试模拟的数据:(来自https://www.rdocumentation.org/packages/FSA/versions/0.8.32/topics/dunnTest)

ponds <- data.frame(pond=as.factor(rep(1:4,each=8)),
pH=c(7.68,7.69,7.70,7.70,7.72,7.73,7.73,7.76,
7.71,7.73,7.74,7.74,7.78,7.78,7.80,7.81,
7.74,7.75,7.77,7.78,7.80,7.81,7.84,NA,
7.71,7.71,7.74,7.79,7.81,7.85,7.87,7.91))
ponds2 <- ponds[complete.cases(ponds),]

如果我运行测试,我会得到这个:

> dunnTest(ponds2$pH,ponds2$pond)
Dunn (1964) Kruskal-Wallis multiple comparison
p-values adjusted with the Holm method.
Comparison           Z     P.unadj      P.adj
1      1 - 2 -2.13700630 0.032597479 0.13038992
2      1 - 3 -2.94934889 0.003184443 0.01592221
3      2 - 3 -0.88480467 0.376261991 1.00000000
4      1 - 4 -2.99180882 0.002773299 0.01663979
5      2 - 4 -0.85480252 0.392660483 0.78532097
6      3 - 4  0.05898698 0.952962480 0.95296248

为了提取p值,我这样做了:

a =dunnTest(ponds2$pH,ponds2$pond)
a = a$res
a$P.adj

我希望它能帮助

相关内容