0
0
R Programmingprogramming~10 mins

join functions (left_join, inner_join) 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 perform a left join of df1 and df2 by the column 'id'.

R Programming
result <- [1](df1, df2, by = "id")
Drag options to blanks, or click blank then click option'
Ainner_join
Bmerge
Cleft_join
Dfull_join
Attempts:
3 left
💡 Hint
Common Mistakes
Using inner_join instead of left_join will drop unmatched rows from df1.
2fill in blank
medium

Complete the code to perform an inner join of df1 and df2 by the column 'key'.

R Programming
result <- [1](df1, df2, by = "key")
Drag options to blanks, or click blank then click option'
Afull_join
Binner_join
Cright_join
Dleft_join
Attempts:
3 left
💡 Hint
Common Mistakes
Using left_join will keep all rows from df1, not just matching ones.
3fill in blank
hard

Fix the error in the code to join df1 and df2 by the column 'user_id' using inner join.

R Programming
joined_data <- [1](df1, df2, by = "user_id")
Drag options to blanks, or click blank then click option'
Ainner_join
Bleft_join
Cmerge
Djoin
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'join' instead of 'inner_join' causes an error.
4fill in blank
hard

Complete the code to perform a left join of df1 and df2 by matching df1's 'id' column to df2's 'user_id' column.

R Programming
result <- left_join(df1, df2, by = c("[1]" = "[2]"))
Drag options to blanks, or click blank then click option'
Aid
Buser_id
Ckey
Dcust_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using by='id' which won't match df2$user_id.
Using by=c('id','user_id') which requires same position columns.
5fill in blank
hard

Fill all three blanks to perform an inner join of df1 and df2 by 'id', handling column conflicts with suffixes '_left' and '_right'.

R Programming
result <- inner_join(df1, df2, by = "[1]", suffix = c("[2]", "[3]"))
Drag options to blanks, or click blank then click option'
Aid
B_left
C_right
D_orig
Attempts:
3 left
💡 Hint
Common Mistakes
Not specifying suffix leads to error if column names overlap.
Reversing the suffix order.