End of Summer - hours only!Up to 80% off on all courses and bundles.-Close
Strings basics
Regular expressions
Modifying strings
18. Remove a character from a string


First, let's start with removing characters. To do this, we will use the sub() function, which looks like this:

sub(pattern, replacement, string)

The arguments are the pattern, the replacement for the first occurrence of the matching part in the string, and the string itself which we want to amend. Since we want to delete these unneeded characters, we're just going to replace them with nothing ("").

So, in "Albany*254_California", we're going to remove the underscore like so:

clients$addresses_cleaned <- sub("_", "", clients$addresses)

Notice that we've assigned the results to a new column, addresses_cleaned.


Use the sub() function to remove all underscores (_) from the names column in the clients data frame. Write it into the new clean_names column.