gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 10:44:50 25 4
gpt4 key购买 nike

我有一个看起来像这样的矩阵(称为结果)

     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,]

关于r - 查找并删除缺失数据大于 5% 的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36964957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com