Hello,
I am using data that contains country and city as variables.
The problem is city, sometimes, contains 2 locations separated by "/" or "-". I solved It using the first condition ("/")...I think
country=c("USA","JPN","JPN","KOR","FRA","FRA","ITA","ITA")
city=c("Miami","Tokyo/Yokohama","Kyoto","Seul","Paris","Lyon/Marseille","Rome","Torino/Firenze")
data1=data.frame(country, city)
data1
data1 %>% mutate(city2=gsub("(.*)/.*","\\1", city))
But I just can't aggregate more conditions, in this case, the "-" text.
I partially solve It, but applying twice the "mutate" command:
country=c("USA","JPN","JPN","KOR","FRA","FRA","ITA","ITA")
city=c("Miami","Tokyo/Yokohama","Kyoto","Seul","Paris","Lyon/Marseille","Rome","Torino-Firenze")
data1=data.frame(country, city)
data1
data1 %>% mutate(city2=gsub("(.*)/.*","\\1", city)) %>% mutate(city2=gsub("(.*)-.*","\\1", city2))
How can I write the conditions in the same "mutate"?
Thanks for your time and interest.