0
0
R Programmingprogramming~20 mins

separate and unite in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Separate and Unite Columns in R
📖 Scenario: You work in a small library. You have a list of books where the author and title are combined in one column. You want to split them into two columns for better organization. Later, you want to join them back into one column.
🎯 Goal: Learn how to use separate() to split one column into two, and unite() to join two columns back into one in R.
📋 What You'll Learn
Create a data frame called books with a column author_title containing exact values
Create a separator variable called sep_char with the exact value used in the data
Use separate() to split author_title into author and title columns
Use unite() to combine author and title back into author_title
Print the final data frame
💡 Why This Matters
🌍 Real World
Libraries, shops, and many businesses often have data combined in one column that needs to be split for better analysis or reporting.
💼 Career
Data analysts and scientists frequently clean and organize data using functions like separate and unite to prepare data for insights.
Progress0 / 4 steps
1
Create the initial data frame
Create a data frame called books with one column author_title containing these exact values: 'Rowling - Harry Potter', 'Tolkien - Lord of the Rings', 'Lewis - Narnia'.
R Programming
Need a hint?

Use data.frame() and c() to create the column with exact strings.

2
Create the separator variable
Create a variable called sep_char and set it to the string ' - ' which is the separator between author and title in author_title.
R Programming
Need a hint?

Assign the exact string ' - ' to sep_char.

3
Separate the author and title columns
Use separate() from the tidyr package to split the author_title column in books into two new columns: author and title. Use the separator stored in sep_char. Save the result back into books.
R Programming
Need a hint?

Use separate(books, col = author_title, into = c('author', 'title'), sep = sep_char).

4
Unite the columns and print the result
Use unite() from tidyr to combine the author and title columns back into one column called author_title, separated by sep_char. Save the result back into books. Then print books.
R Programming
Need a hint?

Use unite(books, col = author_title, author, title, sep = sep_char) and then print(books).