简体   繁体   English

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

[英]dim(X) must have a positive length in R

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**

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 会给你答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM