My gender
variable is a factor with three levels: ""
, "Female"
, and "Male"
. How can I remove ""
from its levels?
You can use
levels(all_trips_v2$gender)[1] <- NA
Here is a test:
x <- factor(c("", "F", "M"))
levels(x)
#[1] "" "F" "M"
## the first level is ""; reset it to NA
levels(x)[1] <- NA
x
#[1] <NA> F M
#Levels: F M
levels(x)
#[1] "F" "M"