Tidyr
5. Don't throw out the old column!
Changing data format
Summary

Instruction

It's good to be able to separate columns, but what if we also want to keep the values in the old column? If we don't want to delete the column we are separating, we simply add the following argument to the separate() statement:

remove = FALSE

For the name column, this would look like:

separate(users, name,
  into = c("first_name", "last_name"),
  sep = "_",
  remove = FALSE)

Exercise

Once again, let's separate domains and email names from email addresses. This time, though, let's keep the email column in the dataset.

Separate email into two columns, email_name and email_domain. Remember to use the sep argument to define the separator (@) and set the remove argument to keep the original column.

Stuck? Here's a hint!

Type:

separate(users, email, 
  into = c("email_name", "email_domain"),
  sep = "@",
  remove = FALSE)