Tidyr
6. Uniting two columns
Changing data format
Summary

Instruction

Oops! We wanted to keep the original column, but we forgot to use remove! What can we do?

One solution is to join two columns using the unite() function. If we wanted to join users' first and last names to make a full name, we'd write:

unite(users, name, first_name, last_name, sep = "_")

The arguments, in the order in which they appear, are the dataset name (users), the new column's name (name), the columns we want to join (first_name and last_name), and the separator used to join them. We've used the underscore character here, but we could have omitted that; R unites using an underscore by default.

Exercise

Join the users dataset columns email_name and email_domain to form a new column named email. Use the unite() function and @ as the new separator.

Stuck? Here's a hint!

Type:

unite(users, email, email_name, email_domain, sep = "@")