R-将apply on numeric matrix与shapiro.test()一起使用会产生错误:all';x';值是相同的

R-将apply on numeric matrix与shapiro.test()一起使用会产生错误:all';x';值是相同的,r,R,我有一个data.framedf,有>110000行。看起来是这样的: traking_id A1_CTRL A2_CTRL A3_CTRL A4_CTRL A5_CTRL A1_DEX A2_DEX A3_DEX A4_DEX A5_DEX 1 ENSMUST00000000001 1.35358e+01 1.03390e+01 1.03016e+01 1.12654e+01 1.22707e+

我有一个data.framedf,有>110000行。看起来是这样的:

  traking_id         A1_CTRL     A2_CTRL     A3_CTRL     A4_CTRL     A5_CTRL     A1_DEX      A2_DEX      A3_DEX      A4_DEX      A5_DEX
1 ENSMUST00000000001 1.35358e+01 1.03390e+01 1.03016e+01 1.12654e+01 1.22707e+01 1.40684e+01 9.15279e+00 1.17276e+01 1.14550e+01 1.46256e+01
2 ENSMUST00000000003 5.01868e-06 5.59107e-06 1.60922e-01 2.45402e-01 2.18614e-01 2.24124e-01 2.88035e-01 7.18876e-06 1.74746e-06 0.00000e+00
...
我感兴趣的是对每行执行shapiro.test两次-一次用于第2:6列中的值,一次用于第7:11列中的值

我想获得函数shapiro.test返回的两个对象列表,以便从中提取p.value列。我想通过使用函数apply来实现,但是我的代码

shapiro.test_CTRL <- apply(data.matrix(df[,2:6]), 1, shapiro.test)
但是,当我使用pearson.test时,一切正常:

pearson.test_CTRL <- apply(data.matrix(df[,2:6]), 1, pearson.test)
shapiro.test(data.matrix(x[1,2:6]))

我想知道为什么在shapiro.test中使用apply会导致错误,以及如何正确执行?

如果您查看shapiro.test的源代码,它有以下行:

...
        x <- sort(x[complete.cases(x)])
        n <- length(x)
        if (is.na(n) || n < 3L || n > 5000L) 
            stop("sample size must be between 3 and 5000")
        rng <- x[n] - x[1L]
        if (rng == 0) 
            stop("all 'x' values are identical")
...
。。。
x
...
        x <- sort(x[complete.cases(x)])
        n <- length(x)
        if (is.na(n) || n < 3L || n > 5000L) 
            stop("sample size must be between 3 and 5000")
        rng <- x[n] - x[1L]
        if (rng == 0) 
            stop("all 'x' values are identical")
...
mtcars[2,] <- 1
apply(mtcars[,2:5], 1, shapiro.test)
f <- function(x) {
  if (diff(range(x)) == 0) list() else shapiro.test(x)
}

apply(mtcars[,2:5], 1, f)