R code
library(tidyverse)dplyr offers several types of joins:
inner_join(x, y, by): Keeps only rows with matching keys in both data frames.left_join(x, y, by): Keeps all rows from x and adds matching data from y.right_join(x, y, by): Keeps all rows from y and adds matching data from x.full_join(x, y, by): Keeps all rows from both data frames.semi_join(x, y, by): Keeps rows from x that have a match in y (no columns from y).anti_join(x, y, by): Keeps rows from x that do not have a match in y.# A tibble: 3 × 3
id name abundance
<dbl> <chr> <dbl>
1 1 Species1 NA
2 2 Species2 85
3 3 Species3 90
Result: All rows from species, scores added where available.
# A tibble: 2 × 3
id name abundance
<dbl> <chr> <dbl>
1 2 Species2 85
2 3 Species3 90
Result: Only rows with id 2 and 3.
# A tibble: 4 × 3
id name abundance
<dbl> <chr> <dbl>
1 1 Species1 NA
2 2 Species2 85
3 3 Species3 90
4 4 <NA> 95
Result: All rows from both, with NA where no match.
by = c("col_in_x" = "col_in_y").Today in preparation for joining data frames with NEON data we will walk through Chapter 19 Joins in R for Data Science. As we did earlier, by putting the examples and exercises in our own Quarto Markdown file, we can create own personal path through the Chapter.
After you Render the qmd file to an html file, export the file to your computer and upload it to Canvas.