0
0
R Programmingprogramming~30 mins

Merging data frames in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Merging data frames
📖 Scenario: You work in a small company that keeps customer and order information in separate tables. You want to combine these tables to see which customers made which orders.
🎯 Goal: Build a simple R program that merges two data frames: one with customer details and one with order details, using a common column.
📋 What You'll Learn
Create two data frames with exact given data
Create a variable for the common column name
Use the merge() function with the common column
Print the merged data frame
💡 Why This Matters
🌍 Real World
Combining customer and order data is common in business to analyze sales and customer behavior.
💼 Career
Data analysts and data scientists often merge data from different sources to prepare for analysis and reporting.
Progress0 / 4 steps
1
Create the initial data frames
Create a data frame called customers with columns customer_id and name containing these rows: (1, "Alice"), (2, "Bob"), (3, "Charlie"). Also create a data frame called orders with columns order_id, customer_id, and product containing these rows: (101, 1, "Book"), (102, 2, "Pen"), (103, 1, "Notebook").
R Programming
Need a hint?

Use data.frame() with vectors for each column to create the data frames.

2
Set the common column name
Create a variable called common_col and set it to the string "customer_id" to use as the key for merging.
R Programming
Need a hint?

Just assign the string "customer_id" to the variable common_col.

3
Merge the data frames
Use the merge() function to merge customers and orders by the column stored in common_col. Save the result in a variable called merged_data.
R Programming
Need a hint?

Use merge(customers, orders, by = common_col) to join the tables on the common column.

4
Print the merged data frame
Write a print() statement to display the merged_data data frame.
R Programming
Need a hint?

Use print(merged_data) to show the combined table.