0

Join the new table one by one with

  1. Left join operation

  2. Right join operation

  3. inner join operation

  4. Full join operation via the species column and save, finally compare the resulting tables.

    old_table <- dplyr :: starwars new_table <- data.frame( species=c("Human", "Ewok", "Droid", "Wookiee", "Gungan"), moje_obliba = c(10,5,3,10,9)))

1 Answers1

0

You can use the following code:

library(dplyr)
# left join
left_join(old_table, new_table, by = "species")
# right join
right_join(old_table, new_table, by = "species")
# inner join
inner_join(old_table, new_table)
# full join
full_join(old_table, new_table)

Output left_join for example:

# A tibble: 87 × 15
   name               height  mass hair_color    skin_color  eye_color birth_year sex    gender    homeworld species films  vehicles  starships moje_obliba
   <chr>               <int> <dbl> <chr>         <chr>       <chr>          <dbl> <chr>  <chr>     <chr>     <chr>   <list> <list>    <list>          <dbl>
 1 Luke Skywalker        172    77 blond         fair        blue            19   male   masculine Tatooine  Human   <chr>  <chr [2]> <chr [2]>          10
 2 C-3PO                 167    75 NA            gold        yellow         112   none   masculine Tatooine  Droid   <chr>  <chr [0]> <chr [0]>           3
 3 R2-D2                  96    32 NA            white, blue red             33   none   masculine Naboo     Droid   <chr>  <chr [0]> <chr [0]>           3
 4 Darth Vader           202   136 none          white       yellow          41.9 male   masculine Tatooine  Human   <chr>  <chr [0]> <chr [1]>          10
 5 Leia Organa           150    49 brown         light       brown           19   female feminine  Alderaan  Human   <chr>  <chr [1]> <chr [0]>          10
 6 Owen Lars             178   120 brown, grey   light       blue            52   male   masculine Tatooine  Human   <chr>  <chr [0]> <chr [0]>          10
 7 Beru Whitesun lars    165    75 brown         light       blue            47   female feminine  Tatooine  Human   <chr>  <chr [0]> <chr [0]>          10
 8 R5-D4                  97    32 NA            white, red  red             NA   none   masculine Tatooine  Droid   <chr>  <chr [0]> <chr [0]>           3
 9 Biggs Darklighter     183    84 black         light       brown           24   male   masculine Tatooine  Human   <chr>  <chr [0]> <chr [1]>          10
10 Obi-Wan Kenobi        182    77 auburn, white fair        blue-gray       57   male   masculine Stewjon   Human   <chr>  <chr [1]> <chr [5]>          10
# … with 77 more rows

data

old_table <- dplyr::starwars 
new_table <- data.frame(species=c("Human", "Ewok", "Droid", "Wookiee", "Gungan"), 
                        moje_obliba = c(10,5,3,10,9))
Quinten
  • 35,235
  • 5
  • 20
  • 53