टेबल्स को खुद से जॉइन करना

dplyr के साथ डेटा जॉइन करना

Chris Cardillo

Data Scientist

themes टेबल

themes
# A tibble: 665 x 3
      id name           parent_id
   <dbl> <chr>              <dbl>
 1     1 Technic               NA
 2     2 Arctic Technic         1
 3     3 Competition            1
 4     4 Expert Builder         1
 5     5 Model                  1
 6     6 Airport                5
 7     7 Construction           5
 8     8 Farm                   5
 9     9 Fire                   5
10    10 Harbor                 5
# … with 655 more rows
dplyr के साथ डेटा जॉइन करना

थीम्स का पदानुक्रम

थीम्स का पदानुक्रम

dplyr के साथ डेटा जॉइन करना

चाइल्ड-पैरेंट टेबल

themes %>%
  inner_join(themes, by = c("parent_id" = "id"))
# A tibble: 544 x 5
      id name.x         parent_id name.y  parent_id.y
   <dbl> <chr>              <dbl> <chr>         <dbl>
 1     2 Arctic Technic         1 Technic          NA
 2     3 Competition            1 Technic          NA
 3     4 Expert Builder         1 Technic          NA
 4     5 Model                  1 Technic          NA
 5     6 Airport                5 Model             1
 6     7 Construction           5 Model             1
 7     8 Farm                   5 Model             1
 8     9 Fire                   5 Model             1
 9    10 Harbor                 5 Model             1
10    11 Off-Road               5 Model             1
# … with 534 more rows
dplyr के साथ डेटा जॉइन करना

सफ़िक्स जोड़ना

themes %>%
  inner_join(themes, by = c("parent_id" = "id"), suffix = c("_child", "_parent"))
# A tibble: 544 x 5
      id name_child     parent_id name_parent parent_id_parent
   <dbl> <chr>              <dbl> <chr>                  <dbl>
 1     2 Arctic Technic         1 Technic                   NA
 2     3 Competition            1 Technic                   NA
 3     4 Expert Builder         1 Technic                   NA
 4     5 Model                  1 Technic                   NA
 5     6 Airport                5 Model                      1
 6     7 Construction           5 Model                      1
 7     8 Farm                   5 Model                      1
 8     9 Fire                   5 Model                      1
 9    10 Harbor                 5 Model                      1
10    11 Off-Road               5 Model                      1
# … with 534 more rows
dplyr के साथ डेटा जॉइन करना

Lord of the Rings थीम्स: पैरेंट

themes %>%
  inner_join(themes, by = c("parent_id" = "id"), suffix = c("_child", "_parent")) %>%
  filter(name_child == "The Lord of the Rings")
# A tibble: 1 x 5
     id name_child            parent_id name_parent                      parent_id_parent
  <dbl> <chr>                     <dbl> <chr>                                       <dbl>
1   566 The Lord of the Rings       561 The Hobbit and Lord of the Rings               NA
dplyr के साथ डेटा जॉइन करना

Lord of the Rings थीम्स: चिल्ड्रन

themes %>%
  inner_join(themes, by = c("parent_id" = "id"), suffix = c("_child", "_parent")) %>%
  filter(name_parent == "The Lord of the Rings")
# A tibble: 3 x 5
     id name_child                 parent_id name_parent           parent_id_parent
  <dbl> <chr>                          <dbl> <chr>                            <dbl>
1   567 The Fellowship of the Ring       566 The Lord of the Rings              561
2   568 The Two Towers                   566 The Lord of the Rings              561
3   569 The Return of the King           566 The Lord of the Rings              561
dplyr के साथ डेटा जॉइन करना

The Lord of the Rings ट्रिलॉजी

Lord of the Rings ट्रिलॉजी थीम्स

dplyr के साथ डेटा जॉइन करना

अभ्यास करते हैं!

dplyr के साथ डेटा जॉइन करना

Preparing Video For Download...