I have data (s_data).
levels(as.factor(s_data$education))
"10th" "11th" "12th" "1st-4th"
"5th-6th" "7th-8th" "9th" "Assoc-acdm"
"Assoc-voc" "Bachelors" "Doctorate" "HS-grad"
"Masters" "Preschool" "Prof-school" "Some-college"
I am trying to collapse samples into one category. For example, "Preschool" and "1st-4th" would be one category, kids. I have tried a couple of approaches with no success.
s_data$education <- case_when(data$education %in% c("1st-4th", "5th-6th", "7th-8th",
"9th","Preschool") ~ "kids") #s_data is an adjusted version of data
This approach tries to replace each row and doesn't yield anything but an error.
I have tried our teacher's approach and when I tried to plot the new data, it did not consist the new category ("kids") at all.
levels(as.factor(s_data$education)) <- c("10th","11th,", "kids", "kids", "kids","7th-8th", "9th", "Assoc-acdm",
"Assoc-voc", "Bachelors","Doctorate","HS-grad", "Masters","kids", "Prof-school",
"Some-college")
Do you have ideas how can I collapse these levels into one category?
Thank you!