dim(X)在R中的长度必须为正值

时间:2021-01-29 16:10:32

I want to see how many positive and negative I have in a matrix I simply use the following command to get the negative values but I get error

我想知道我在一个矩阵中有多少个正的和负的我只是用下面的命令来得到负的值但是我得到了错误

apply(m[,2], 2, function(x) length(x[x<0]))

My matrix look like following and named m

我的矩阵如下,并命名为m。

    row.names   logFC        AveExpr       t         P.Value    adj.P.Val       B
1   AFFX    0.254330303 -0.0273913479   2.790941    0.005346628 0.9936675   -2.351052
2   AFFX-   0.144249680 -0.0081323315   2.744752    0.006154509 0.9936675   -2.470447
3   AFFX-T  0.129062121 -0.0072936248   2.730567    0.006423832 0.9936675   -2.506720
4   AFFy    0.105893838 -0.0084886157   2.672831    0.007632963 0.9936675   -2.652445
5   AFfm    0.146253131 -0.0123657559   2.617852    0.008970330 0.9936675   -2.788357
6   20uy    1.033582071 0.9319210383    2.476302    0.013425076 0.9936675   -3.125444
7   2196    0.099556431 -0.0061285974   2.451229    0.014392052 0.9936675   -3.183222



**Error in apply(m[, 2], 2, function(x) length(x[x < 0])) : 
  dim(X) must have a positive length**

1 个解决方案

#1


4  

You can just type:

你可以类型:

sum(m<0)

which gives you the number of negative values of the whole matrix. If you want it for each row or column, then

它给出了整个矩阵的负数。如果您想让它用于每一行或每一列,那么

colSums(m<0)

and

rowSums(m<0)

will give you the answer

会给你答案吗?

#1


4  

You can just type:

你可以类型:

sum(m<0)

which gives you the number of negative values of the whole matrix. If you want it for each row or column, then

它给出了整个矩阵的负数。如果您想让它用于每一行或每一列,那么

colSums(m<0)

and

rowSums(m<0)

will give you the answer

会给你答案吗?