peakstatus
peakstatus

Reputation: 441

R - Remove Empty Category in Summary

I'm working on cleaning a dataset I plan to use for analysis. Some records were coded as '' instead of NA's, so I'm converting all these records to be NA and then dropping them from my dataset.

After dropping these records, the '' factor group is still showing up in the summary of the data. Is there anyway to fix this?

Example Code:

surgery$gender[surgery$gender == ""] <- NA
surgery = surgery %>% drop_na(gender)
surgery$gender = as.factor(surgery$gender)

summary(surgery)

Example Summary Output:

enter image description here

Upvotes: 1

Views: 731

Answers (1)

G5W
G5W

Reputation: 37641

surgery$gender = droplevels(surgery$gender)

Upvotes: 3

Related Questions