Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write an R program to merge two data frames by a common column.

Easy

Problem Statement

Write an R program to merge two data frames by a common column.

Sample Input

Data Frame 1: 
 ID Name
1 1 John
2 2 Alice
3 3 Bob
Data Frame 2: 
 ID Age
1 1 25
2 2 30
3 3 22

Sample Output

  ID  Name Age
1  1  John  25
2  2 Alice  30
3  3   Bob  22

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
# Predefined structure df1 <- data.frame(ID = c(1, 2, 3), Name = c("John", "Alice", "Bob")) df2 <- data.frame(ID = c(1, 2, 3), Age = c(25, 30, 22)) merged_df <- merge(df1, df2, by = "ID") print(merged_df)
Log in or sign up to run or submit your code.Log inSign up
Input
Data Frame 1: 
 ID Name
1 1 John
2 2 Alice
3 3 Bob
Data Frame 2: 
 ID Age
1 1 25
2 2 30
3 3 22
Expected Output
  ID  Name Age
1  1  John  25
2  2 Alice  30
3  3   Bob  22