Last active
December 6, 2018 09:42
-
-
Save cecilesauder/7e431f2b341f70df9853e995672c09e3 to your computer and use it in GitHub Desktop.
Si je join par c("Name", "Species"), je récupère pas les Species et Gender de df2, même si y a pas d'ambiguité, Si je join juste par Name j'ai des doublons de Name pour un DOG qui aurait le même Name qu'un CAT de df2, moi je voudrais que ça me sorte le premier tableau mais sans les NA , c'est possible ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` r | |
library(tidyverse) | |
df1 <- tibble(Name = c("Pastis", "Mojito", "Binouze"), | |
Species = c("CAT", NA, "DOG")) | |
df2 <- tibble(Name = c("Pastis", "Mojito", "Binouze", "Jack", "Binouze"), | |
Species = c("CAT", "CAT", "DOG", "DOG", "CAT"), | |
Gender = c("M", "M", "F", "M", "F")) | |
left_join(df1,df2, by = c("Name", "Species")) | |
#> # A tibble: 3 x 3 | |
#> Name Species Gender | |
#> <chr> <chr> <chr> | |
#> 1 Pastis CAT M | |
#> 2 Mojito <NA> <NA> | |
#> 3 Binouze DOG F | |
left_join(df1,df2, by = c("Name")) | |
#> # A tibble: 4 x 4 | |
#> Name Species.x Species.y Gender | |
#> <chr> <chr> <chr> <chr> | |
#> 1 Pastis CAT CAT M | |
#> 2 Mojito <NA> CAT M | |
#> 3 Binouze DOG DOG F | |
#> 4 Binouze DOG CAT F | |
``` | |
<sup>Created on 2018-12-06 by the [reprex package](https://reprex.tidyverse.org) (v0.2.1)</sup> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment