Mutate and replace strings to new column

Hi! Welcome!

If that’s the exact code you’re running, then I think the problem is that you haven’t actually assigned a new name to the mutated data frame. This is a really common point of confusion for people new to R! You get a display of the result in the console because objects print to the console by default (e.g., if you type test in the console, then you’ll see the test data frame printed in the console output).

Try:

test2 <- test %>% 
  mutate(new_col = str_replace(old_col, "3+3", "1"))

This will not print anything to the console (because you did something with the mutated data frame — assigned it to a new name — so the default print action did not kick in), but you should then be able to ask for test2 and see the mutated results.

If you need some pointers for good resources for getting up to speed with R, we’ve got a great thread for that:

And keep asking questions here! :grin:

3 Likes