重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

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

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP