Write R code to merge 2 data frames together. The output will show a table containing the merged data.
Combining data from multiple sources is a common task in data analysis. R provides functions like merge()
to handle this. Below is an exmaple of the merge function in action.
merge()
# Sample data frames
customers <- data.frame(
customer_id = c(1, 2, 3),
name = c("Alice", "Bob", "Charlie")
)
orders <- data.frame(
order_id = c(101, 102, 103),
customer_id = c(1, 2, 2),
amount = c(50, 75, 100)
)
# Merge on customer_id
merged_data <- merge(customers, orders, by = "customer_id")
merged_data
Try inputting the above co