I got a factor data set df that looks like this:
df <- data.frame(attend = c("yes", "no", "no", "iap", "yes", "yes", "iap"),
sex = c("male", "female", "female", "male", "female", "male", "female"))
df$attend <- as.factor(df$attend)
df$sex <- as.factor(df$sex)
df
| attend | sex |
|---|---|
| yes | male |
| no | female |
| no | female |
| iap | male |
| yes | female |
| yes | male |
| iap | female |
I want to remove only the iap level from the attend variable.(I don't want to remove the entire row, what I'm looking for is to remove the level iap, so that it becomes a missing value under variable attend)
I tried the below code to remove it but it occurs an error saying: Error in UseMethod("droplevels") : no applicable method for 'droplevels' applied to an object of class "character".
df$attend <- droplevels(levels(df$attend)[4])
Much appreciated it if someone can help.