查找并删除缺失数据大于 5% 的行

find and delete rows which have greater than 5% missing data

我有一个如下所示的矩阵(称为结果)

     id1 id2 id3 id4 id5 id6 id7 id8 id9
snp1  1   2   0   NA  1   1   1   2   1
snp2  2   2   2   2   0   2   NA  NA  0
snp3  NA  NA  1   NA  0   NA  NA  2   2

到目前为止,我已经使用

删除了完全用 NA 填充的行和列
indexsnp=apply(results,1,
function(x) length(which(is.na(x)==T)))
indexsnp=which(indexsnp==length(results[1,]))
indexsample=apply(results,2,
function(x) length(which(is.na(x)==T)))
indexsample=which(indexsample==length(results[,1]))

#get rid of indexes
results=results[-indexsnp,]
results=results[,-indexsample]

我的数据集中还有很多 NA,所以现在我想看看哪个 snp 的调用率低于 95%(即哪些行包含超过 5% 的 NA),然后删除这些行。我不知道该怎么做。我试过了

snpsum.col <- col.summary(results)
library(snpStats)
call <- 0.95
use <- with(snpsum.col, (!is.na(Call.rate) & Call.rate >= call))
use[is.na(use)] <- FALSE              
cat(ncol(results)-sum(use),"SNPs will be removed due to low call  
rate.\n")
genotype <- genotype[,use]
snpsum.col <- snpsum.col[use,]

但我收到错误

Error in col.summary(results) : not a SnpMatrix object

还有其他方法吗?

如果m是这样的矩阵,做

m <- m[is.na(m)%*%rep(1,ncol(m))<=ncol(m)*0.05,]