温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

R语言移除缺失值 NA

发布时间:2020-10-08 14:29:15 来源:网络 阅读:3907 作者:qizok 栏目:编程语言


有三种方法  !is.na  , na.omit, complete.cases

> d <- read.table("GWAS_s2.qassoc", header=T, stringsAsFactors=F)  

// 文件行数
> nrow(d)
[1] 431493

> d1 <- subset(d, select=c("CHR", "SNP", "BP", "P"))  

// 计算非NA 的行数

> num.bool <- complete.cases(d1)
> head(num.bool)
[1] FALSE  TRUE  TRUE FALSE  TRUE  TRUE  

> sum(num.bool) 
[1] 363836                                                                                                            
                                                                                                                            
> dn1 <- d1[which(!is.na(d1$P)),]                                                                                                                                                 
> nrow(dn1)                                                                                                                                                                       
[1] 363836

> dn2 <- na.omit(d1)
> nrow(dn2)                                                                                                                                                            
[1] 363836

> dn3 <-d1[complete.cases(d1[,4]),]                                                                                                                                               
> nrow(dn3)                                                                                                                                                                      
[1] 363836


> dn4 <-d1[complete.cases(d1),]                                                                                                                                                  
> nrow(dn4)
[1] 363836


方法三和方法四, 一个是根据第四列是否为NA判断的, 一个是根据所有列。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI