Hey, I´m trying to rename some string values ( that contain specific parts) to another strings. Tried in the starwars tibble (dyplr). I want to rename many of them differently.
.*Na is for Naboo
.*oo is for Tatooine
df_test1 <- starwars %>%
mutate(new_homeworld = gsub ("[.*Na.* | .*oo.*]", "A" ,homeworld)
df_test1
It did not work
Also tried
df_test2 <- starwars %>%
mutate(new_homeworld = case_when(homeworld == ".*Na.*" ~ "A",
homeworld == ".*oo.*" ~ "B",
TRUE ~ "C"))
I don't what you mean ?
did you get an error ? what error did you get ?
did it run without error, but give an improper result ? how so ?
ps. it might be helpful to know how to properly format code and console output that you post here. Using proper code formatting makes the site easier to read, prevents confusion (unformatted code can get garbled by the forum software ), and is generally considered the polite thing to do. Check out this FAQ to find out how — it's as easy as the click of a button! :