Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 209770

R find replace in data frame

$
0
0

I tried to find an answer for this in other posts but nothing seemed to be working.

I have a data set where people answered the city they were in using a free response format. Therefore for each city, people identified in many different ways. For example, those living in Atlanta might have written "Atlanta", "atlanta", "Atlanta, GA" and so on.

There are 12 cities represented in this data set. I'm trying to clean this variable so each city is written consistently. Is there a way to do this efficiently for each city? I've tried mutate_if and str_replace_all but can't seem to figure it out (see my code below)

all_data_city <- mutate_if(all_data_city, is.character, 
                str_replace_all, pattern = "Atlanta, GA",  
                replacement = "Atlanta")
all_data_city %>%
  str_replace_all(c("Atlanta, GA"& "HCA Atlanta"& "HCC Atlanta"&
                      "Suwanee"& "Suwanee, GA"& "suwanee"), = "Atlanta")

Viewing all articles
Browse latest Browse all 209770

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>