"Incorrect number of dimensions" 在 R 中建立索引时出错

"Incorrect number of dimensions" error when indexing in R

我正在第二次分析我论文的一些结果,因为我有新数据,我使用了 dunntest() 函数并获得了这样的 table:

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

希望对您有所帮助