189 8069 5689

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://jkwzsj.com/article/peicgg.html

其他资讯