ConnorO
ConnorO

Reputation: 13

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...

Upvotes: 0

Views: 1296

Answers (1)

varontron
varontron

Reputation: 1157

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

Upvotes: 1

Related Questions