简体   繁体   English

R:从数据帧中删除NA值

[英]R: Removing NA values from a data frame

A bit of a newbie question: I have a data frame with 7,000 observations of 15 variables and 800+ NA values. 一个新手问题:我有一个数据框,其中包含15个变量和800多个NA值的7,000个观察值。

I have figured out how to identify the rows with 4 or more NA values: DF[rowSums(is.na(DF)) >= 4, ] , but I'd like to remove the records with 4 or more NA values from the DF . 我想出了如何识别具有4个或更多NA值的行: DF[rowSums(is.na(DF)) >= 4, ] ,但我想从中删除具有4个或更多NA值的记录。 DF Can someone let me know where to put the na.rm = T if this is the best way? 如果这是最好的方法,有人可以让我知道将na.rm = T放在哪里吗?

Many thanks, I'm new to R and have looked and looked... 非常感谢,我是R新手,已经看过了……

Your condition identifies the rows you want to omit. 您的条件标识了要忽略的行。 Negate it to ID the rows you want to keep, then store the result in the variable (or another one.): 将其取反以标识要保留的行,然后将结果存储在变量(或另一个变量)中:

DF <- DF[!(rowSums(is.na(DF)) >= 4), ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM