How to join two tables (tibbles) by *list* columns in R

0 votes

If the list of both key variables is identical, I want the row to be included in the final table, and if not then it should not be included. In the below example there are two key variables x and y. So the result should be only the first row since it's the only identical one in both key variables.

Refer to the code below:

tib1 <- tibble(x = list(1, 2, 3), y = list(4, 5, 6))
tib1
# A tibble: 3 × 2
      x         y
 <list>    <list>
1 <dbl [1]> <dbl [1]>
2 <dbl [1]> <dbl [1]>
3 <dbl [1]> <dbl [1]>

tib2 <- tibble(x = list(1, 2, 4, 5), y = list(4, c(5, 10), 6, 7))
tib2
# A tibble: 4 × 2
      x         y
 <list>    <list>
1 <dbl [1]> <dbl [1]>
2 <dbl [1]> <dbl [2]>
3 <dbl [1]> <dbl [1]>
4 <dbl [1]> <dbl [1]>

dplyr::inner_join(tib1, tib2)
Apr 5, 2018 in Data Analytics by DataKing99
• 8,100 points
34 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

You can use the hash from digest as follows:

tib1 <- tibble(x = list(1, 2, 3), y = list(4, 5, 6))
tib2 <- tibble(x = list(1, 2, 4, 5), y = list(4, c(5, 10), 6, 7))

tib1 <- mutate_all(tib1, funs(hash = map_chr(., digest::digest)))
tib2 <- mutate_all(tib2, funs(hash = map_chr(., digest::digest)))

dplyr::inner_join(tib1, tib2, c('x_hash', 'y_hash')) %>%
  select(x.x, x.y)

answered Apr 5, 2018 by kappa3010
• 2,010 points

Related Questions In Data Analytics

0 votes
1 answer

How to sort a data frame by columns in R?

You can just use the order function ...READ MORE

answered Apr 10, 2018 in Data Analytics by darklord
• 6,140 points
47 views
0 votes
1 answer

How to use group by for multiple columns in dplyr, using string vector input in R?

dplyr added versions for group_by. This allows you ...READ MORE

answered Apr 12, 2018 in Data Analytics by CodingByHeart77
• 3,680 points

edited Apr 12, 2018 by CodingByHeart77 1,620 views
0 votes
1 answer

How to convert a list to data frame in R?

Let's assume your list of lists is ...READ MORE

answered Apr 12, 2018 in Data Analytics by nirvana
• 3,040 points

edited Apr 12, 2018 by nirvana 1,272 views
0 votes
1 answer

How to sum a variable by group in R?

Easily by using Aggregate Func(): aggregate(x$points, by=list(Players=x$Players), FUN=sum) or ...READ MORE

answered Apr 13, 2018 in Data Analytics by CodingByHeart77
• 3,680 points

edited Apr 13, 2018 by CodingByHeart77 3,183 views
0 votes
3 answers

How to remove NA values with dplyr::filter()

Null values have no notion of equality ...READ MORE

answered Apr 11 in Data Analytics by Zane
2,720 views
0 votes
1 answer

How can I use parallel so that it preserves the list of data frames

You can use pmap as follows: nc <- ...READ MORE

answered Apr 4, 2018 in Data Analytics by kappa3010
• 2,010 points
18 views
0 votes
1 answer

Join list of data.frames using map() call

You can use Reduce set.seed(24) r1 <- map(c(5, 10, 15), ...READ MORE

answered Apr 5, 2018 in Data Analytics by darklord
• 6,140 points
8 views
0 votes
1 answer

How to use dplyr functions such as filter() inside nested data frames with map()

You can use map() call as follows:  map(full, ...READ MORE

answered Apr 6, 2018 in Data Analytics by darklord
• 6,140 points
84 views
0 votes
1 answer
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.