首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R "complete.cases“一种而不是另一种?

R "complete.cases“一种而不是另一种?
EN

Stack Overflow用户
提问于 2014-04-01 00:21:57
回答 1查看 248关注 0票数 0

我试图使用complete.cases从文件中清除NAs。

我一直在使用这个网站的帮助,但它不起作用,我不再确定我试图做的是可能的。

代码语言:javascript
复制
juulDataRaw <- read.csv(url("http://blah"));
juulDataRaw[complete.cases(juulDataRaw),]

我试过这个(这里的例子之一)

代码语言:javascript
复制
dog<-structure(list(Sample = 1:6
,gene = c("ENSG00000208234","ENSG00000199674","ENSG00000221622","ENSG00000207604","ENSG00000207431","ENSG00000221312")
,hsap = c(0,0,0,0,0,0)
,mmul = c(NA,2,NA,NA,NA,1)
,mmus = c(NA,2,NA,NA,NA,2)
,rnor = c(NA,2,NA,1,NA,3)
,cfam = c(NA,2,NA,2,NA,2))
,.Names = c("gene", "hsap", "mmul", "mmus", "rnor", "cfam"), class = "data.frame", row.names = c(NA, -6L))
dog[complete.cases(dog),]

而且这很管用。

  • 所以我的能做吗?
  • 这两者有什么区别呢?
  • 它们不是都是数据帧吗?
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-01 00:39:31

您在数值周围有引号,因此它们被作为因素读入。这使得" NA“只是另一个字符串,而不是R。

代码语言:javascript
复制
> juulDataRaw[] <- lapply(juulDataRaw, as.character)
> juulDataRaw[] <- lapply(juulDataRaw, as.numeric)
Warning messages:
1: In lapply(juulDataRaw, as.numeric) : NAs introduced by coercion
2: In lapply(juulDataRaw, as.numeric) : NAs introduced by coercion
3: In lapply(juulDataRaw, as.numeric) : NAs introduced by coercion
> juulDataRaw[complete.cases(juulDataRaw),]
       age height igf1 weight
55    6.00  111.6   98   19.1
57    6.08  116.7  242   21.7
61    6.26  120.3  196   24.7
66    6.40  115.5  179   19.6
69    6.42  115.6  126   20.6
71    6.43  116.1  142   20.2
80    6.61  130.3  236   28.0
81    6.63  122.2  148   21.6
83    6.70  126.2  174   26.1
84    6.72  125.6  136   22.6
85    6.72  121.0  164   24.4
snipped remaining output.....
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22774613

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档