I have a little question about joins in dplyr package in R. I have 2 (big) dataframes, that I want to join. They have multiple columns in common, but one is enough to join them. For now I do something like this:
tab1 <- data.frame(id= c("a", "b", "c", "d"),
name = c("Mike", "Anna", "John", "Edward"),
score = c(10, 20, 30, 20)
tab2 <- data.frame(id= c("a", "b", "c", "d"),
name = c("Mike", "Anna", "John", "Edward"),
color = c("red", "blue", "blue", "orange")
dplyr::left_join(x, y)
This solution is ok, but you can see that the join is using id and name as keys, even if we do not need both. My worry, since I work with bigger dataframes and I have to do this with multiple iteration, is that using all the same-name columns would take useless time.
I can of course specify by = id, but then left_join will keep name.x AND name.y.
So I have 2 questions:
- Does a join with multiple keys (say 20 keys) takes more time than a join with one key?
- If the answer is yes, is there a simple mean to specify one key and drop the other duplicated columns from one table?
I hope my question is clear, do not hesitate to ask precisions, many thanks!