Skip to contents

like dplyr::inner_join while ignore the same columns in right tibble

Usage

inner_expand(x, y, by = NULL)

Arguments

x

left tibble

y

right tibble

by

columns to join by

Value

tibble

Examples


tb1 <- head(mini_diamond, 4)
tb2 <- tibble::tibble(
  id = c("id-2", "id-4", "id-5"),
  carat = 1:3,
  price = c(1000, 2000, 3000),
  newcol = c("new2", "new4", "new5")
)

left_expand(tb1, tb2, by = "id")
#> # A tibble: 4 × 8
#>   id    carat cut   clarity price     x     y newcol
#>   <chr> <dbl> <chr> <chr>   <int> <dbl> <dbl> <chr> 
#> 1 id-1   1.02 Fair  SI1      3027  6.25  6.18 NA    
#> 2 id-2   1.51 Good  VS2     11746  7.27  7.18 new2  
#> 3 id-3   0.52 Ideal VVS1     2029  5.15  5.18 NA    
#> 4 id-4   1.54 Ideal SI2      9452  7.43  7.45 new4  

full_expand(tb1, tb2, by = "id")
#> # A tibble: 5 × 8
#>   id    carat cut   clarity price     x     y newcol
#>   <chr> <dbl> <chr> <chr>   <int> <dbl> <dbl> <chr> 
#> 1 id-1   1.02 Fair  SI1      3027  6.25  6.18 NA    
#> 2 id-2   1.51 Good  VS2     11746  7.27  7.18 new2  
#> 3 id-3   0.52 Ideal VVS1     2029  5.15  5.18 NA    
#> 4 id-4   1.54 Ideal SI2      9452  7.43  7.45 new4  
#> 5 id-5  NA    NA    NA         NA NA    NA    new5  

inner_expand(tb1, tb2, by = "id")
#> # A tibble: 2 × 8
#>   id    carat cut   clarity price     x     y newcol
#>   <chr> <dbl> <chr> <chr>   <int> <dbl> <dbl> <chr> 
#> 1 id-2   1.51 Good  VS2     11746  7.27  7.18 new2  
#> 2 id-4   1.54 Ideal SI2      9452  7.43  7.45 new4