如何查找零百分比超过60%的列

时间:2019-01-24 17:24:02

标签: r

我有这样的数据

    df<-structure(list(X1 = c(1.419, 1.294, 3.558, 0.17, 0, 0.03, 0.129, 
0, 0.105, 0, 1.812, 0.237, 0, 5.241), X2 = c(0, 0, 0, 0.175, 
0, 0, 0.073, 0, 0.079, 0, 3.204, 0.062, 0, 3.864), X3 = c(0, 
0.081, 0.291, 0.013, 0, 0, 0.023, 0, 0.12, 0, 2.13, 0, 0, 4.383
), X4 = c(0.868, 0.472, 0.002, 0.604, 0.343, 0, 0.097, 0, 0.149, 
0, 2.741, 0.1, 0, 5.231)), class = "data.frame", row.names = c(NA, 
-14L))

我想知道哪些行占az 0行的60%以上

我知道如何删除完全为零的那些,但是我找不到行中具有50%或60%的那​​些

1 个答案:

答案 0 :(得分:0)

一个选择是在逻辑read -rp "Please, type/paste the working path (folder) you wish to link this scripts: " working_dir working_dir=${working_dir//\\//} 上的colMeans

matrix

如果我们要查找具有超过50%0的行,请对thresh <- 0.5 names(df)[colMeans(df == 0) >= thresh] 进行相同操作

rowMeans