I have a data set in R containing multiple columns. One column room_type contains either the string values Entire home/apt or Shared room or Private room or it's blank. I want to create a new column room_type_new where string values are based on the column room_type. Note: There are over 100 000 rows in the data set.
See below:
room_type room_type_new
Entire home/apt Entire home
Private room Shared home
Shared room Shared home
NA NULL
I tried this code, which prints the correct output but doesn't pass the new values to room_type_new:
data1$room_type <- as.character(data1$room_type)
data1$room_type_new <- NA
data1$room_type_new <- as.character(data1$room_type_new)
data1%>%
mutate(room_type_new = case_when(.$room_type %in% c("Entire home/apt") ~ "Entire home",.$room_type %in% c("Private room", "Shared room") ~ "Shared home")