Search code examples
rmergetidyverse

how program to join 2 different tables based on which one has the highest number of rows, with tidyverse?


How program to join 2 different tables based on which one has the highest number of rows, with tidyverse? Now, the total_number_views_ndinstict has only 8 but in the future this may have more rows than the second total_number_views_unique_na which currently has 10 rows. I need both columns in the joined table.

Here is the first table:

> total_number_views_ndinstict
    # A tibble: 8 × 2
      app_name                    n_distinct_users
      <chr>                                  <int>
    1 animals_to_groups                          2
    2 cage_randomiser                            5
    3 combo_cor                                  1
    4 crispr_screen_viz                         21
    5 dep_map_bem                                4
    6 growth_rate_explorer                       3
    7 moprospector                               2
    8 translatability_single_gene               17

And the second table is

> total_number_views_unique_na
# A tibble: 10 × 2
   app_name                    users_na
   <chr>                          <int>
 1 animals_to_groups                 21
 2 cage_randomiser                   14
 3 combo_cor                         14
 4 crispr_screen_viz                  1
 5 dep_map_bem                        0
 6 dtp_browser_prod                   6
 7 flat                              81
 8 growth_rate_explorer              48
 9 moprospector                       0
10 translatability_single_gene        2

Can someone help?


Solution

  • A full join will keep theh values of both tables

    library(dplyr)
    full_join(total_number_views_ndinstict, total_number_views_unique_na)