快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

R语言移除缺失值NA

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

创新互联建站是一家专注于成都网站建设、网站设计与策划设计,巨野网站建设哪家好?创新互联建站做网站,专注于网站建设10余年,网设计领域的专业建站公司;建站业务涵盖:巨野等地区。巨野做网站价格咨询:028-86922220

> 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判断的, 一个是根据所有列。


本文标题:R语言移除缺失值NA
本文地址:http://6mz.cn/article/peicgg.html

其他资讯