在我的脚本的某个时刻,我喜欢在我的 data.frame $ c中看到缺少值的数量 $ c>并显示它们。 在我的情况下,我有:
At some point in my script I like to see the number of missing values in my data.frame and display them. In my case I have:
out <- read.csv(file="...../OUT.csv", na.strings="NULL") sum(is.na(out$codeHelper)) out[is.na(out$codeHelper),c(1,length(colnames(out)))]它工作得很好。 然而,最后一个命令显然给了我整个 data.frame 其中 NA 是 TRUE ,例如:
It works perfectly fine. However, the last command obviously gives me the whole data.frame where the NA is TRUE, eg:
5561 Yemen (PDR) <NA> 5562 Yemen (PDR) <NA> 5563 Yemen (PDR) <NA> 5564 Yemen (PDR) <NA> 5565 Yemen (PDR) <NA> 5566 Yemen (PDR) <NA> 5567 Yemen (PDR) <NA> 5568 Yemen (PDR) <NA> 5601 Zaire (Democ Republic Congo) <NA> 5602 Zaire (Democ Republic Congo) <NA> 5603 Zaire (Democ Republic Congo) <NA> 5604 Zaire (Democ Republic Congo) <NA> 5605 Zaire (Democ Republic Congo) <NA>有一个大框架和很多NAs看起来很混乱。 对我来说重要的只是NA发生的地方,哪个国家(在第二列)在第三列中缺少值。
With a big frame and a lot of NAs that looks pretty messy. Important to me is only where the NA occurs i.e which country (in the second column) has a missing value in the third column.
那么我怎么只能为每个国家显示一行?
So how can i only display a single row for each country?
它应该是这样的:
1 Yemen (PDR) <NA> 2 Zaire (Democ Republic Congo) <NA> 3 USA <NA> 4 W. Samoa <NA>推荐答案
unique(c(1 ,2,3,4,4))
将给你
1 2 3 4
1 2 3 4
so
unique(out [is.na(out $ codeHelper),c(1,length(colnames(out)))])
应该是你要找的?
更多推荐
每个NA值只显示一行
发布评论