0

I'm trying to remove any strings that contains the word "Seattle" in the column named "County" in the table named Population

    Population %>%
    mutate( str_replace(County, "Seattle", ""))

It gives me an error message.

curveball
  • 4,320
  • 15
  • 39
  • 49

1 Answers1

0

I suspect you are getting an error because in your mutate you aren't defining what column you're mutating...

Also, I think you will have better success with an if_else statement detecting the string pattern of Seattle using grepl and then replacing the contents. Below is the code I've used for something similar.

Population %>%
mutate(County = if_else(grepl("Seattle", County),"",County)) 

The grepl will detect the string pattern in the County field and provide a TRUE/FALSE return. From there, you just define what to do if it is found to be true, i.e. replace it with nothing (""), or keep the value as is (County).

Dave
  • 1
  • 2