摘要在同时使用na.omit和complete.cases后仍显示NA [英] summary still shows NAs after using both na.omit and complete.cases

查看:144
本文介绍了摘要在同时使用na.omit和complete.cases后仍显示NA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名使用R的研究生,并且正在阅读有关从数据帧中删除包含NA的行的其他Stack Overflow答案.我已经尝试了na.omit和complete.cases.当同时使用两者时,它表明具有NA的行已被删除,但是当我编写summary(data.frame)时,它仍包含NA.带有NA的行实际上已删除还是我做错了?

I am a grad student using R and have been reading the other Stack Overflow answers regarding removing rows that contain NA from dataframes. I have tried both na.omit and complete.cases. When using both it shows that the rows with NA have been removed, but when I write summary(data.frame) it still includes the NAs. Are the rows with NA actually removed or am I doing this wrong?

na.omit(Perios)
summary(Perios)

Perios[complete.cases(Perios),]
summary(Perios)

推荐答案

  1. 错误是您实际上没有分配na.omit的输出!

Perios <- na.omit(Perios)

如果您知道NA出现在哪一列,那么您就可以这样做

If you know which column the NAs occur in, then you can just do

Perios[!is.na(Perios$Periostitis),]

或更笼统地说:

Perios[!is.na(Perios$colA) & !is.na(Perios$colD) & ... ,]

然后作为R的一般安全提示,输入na.fail断言其有效:

Then as a general safety tip for R, throw in an na.fail to assert it worked:

na.fail(Perios)  # trust, but verify! Die Paranoia ist gesund.

这篇关于摘要在同时使用na.omit和complete.cases后仍显示NA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆