简体   繁体   中英

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.

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 . Can someone let me know where to put the na.rm = T if this is the best way?

Many thanks, I'm new to R and have looked and looked...

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), ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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