0
0
R Programmingprogramming~10 mins

Merging data frames in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to merge two data frames by the column 'id'.

R Programming
merged_df <- merge(df1, df2, by = [1])
Drag options to blanks, or click blank then click option'
A"score"
B"name"
C"age"
D"id"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the column name in quotes.
Using a column name that does not exist in both data frames.
2fill in blank
medium

Complete the code to perform a left join of df1 with df2 by 'id'.

R Programming
merged_df <- merge(df1, df2, by = "id", all.x = [1])
Drag options to blanks, or click blank then click option'
ATRUE
BNA
CFALSE
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using FALSE instead of TRUE for all.x.
Confusing all.x with all.y.
3fill in blank
hard

Fix the error in the code to merge df1 and df2 by columns 'id' and 'date'.

R Programming
merged_df <- merge(df1, df2, by = [1])
Drag options to blanks, or click blank then click option'
Ac(id, date)
B"id, date"
Cc("id", "date")
Dlist("id", "date")
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single string with comma-separated names.
Using unquoted column names.
4fill in blank
hard

Fill both blanks to merge df1 and df2 by 'id' and keep all rows from both data frames.

R Programming
merged_df <- merge(df1, df2, by = [1], all.x = [2], all.y = TRUE)
Drag options to blanks, or click blank then click option'
A"id"
BTRUE
CFALSE
D"date"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column name for merging.
Setting all.x to FALSE which drops rows from df1.
5fill in blank
hard

Fill all three blanks to merge df1 and df2 by 'id', keep all rows from df1, and suffix overlapping columns with '_df1' and '_df2'.

R Programming
merged_df <- merge(df1, df2, by = [1], all.x = [2], suffixes = c([3], "_df2"))
Drag options to blanks, or click blank then click option'
A"id"
BTRUE
C"_df1"
DFALSE
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around suffix strings.
Setting all.x to FALSE which drops rows from df1.
Using wrong column name for merging.