You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The keep argument, to preserve join key columns from both the x and y data frames (when the name differs), is available for all mutate joins except inner_join. It looks like it should be straightforward to add in the existing call to join_mutate().
Unlike with left/right/full joins, the paired key columns in an inner join will always be identical so admittedly it's less useful to retain both, but still potentially useful in some applications (e.g. to facilitate subsequent joins, or for later data validation).
library(dplyr, warn.conflicts=FALSE)
df1<- tibble(
id1=letters[1:3],
x=1:3
)
df2<- tibble(
id2=letters[1:2],
y=1:2
)
# use 'keep' arg to retain both join key columns (id1 and id2)
left_join(df1, df2, by= c("id1"="id2"), keep=TRUE)
#> # A tibble: 3 x 4#> id1 x id2 y#> <chr> <int> <chr> <int>#> 1 a 1 a 1#> 2 b 2 b 2#> 3 c 3 <NA> NA# keep arg also avail for full_join, right_join, and nest_join# but inner_join doesn't have keep arg so can't retain join key from y
inner_join(df1, df2, by= c("id1"="id2"), keep=TRUE)
#> # A tibble: 2 x 3#> id1 x y#> <chr> <int> <int>#> 1 a 1 1#> 2 b 2 2
The
keep
argument, to preserve join key columns from both thex
andy
data frames (when the name differs), is available for all mutate joins exceptinner_join
. It looks like it should be straightforward to add in the existing call tojoin_mutate()
.Unlike with left/right/full joins, the paired key columns in an inner join will always be identical so admittedly it's less useful to retain both, but still potentially useful in some applications (e.g. to facilitate subsequent joins, or for later data validation).
Created on 2020-10-31 by the reprex package (v0.3.0)
The text was updated successfully, but these errors were encountered: