From 3de6a514312c9c45faf9c07cd63669965fc695e8 Mon Sep 17 00:00:00 2001 From: Ethan White Date: Tue, 3 Sep 2024 06:58:14 -0400 Subject: [PATCH] Introduce pull for extracting vectors from data frames --- exercises/extracting-vectors-from-data-frames-R.md | 2 +- materials/converting-dataframes-vectors.md | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/exercises/extracting-vectors-from-data-frames-R.md b/exercises/extracting-vectors-from-data-frames-R.md index eabe1bf75..869846354 100644 --- a/exercises/extracting-vectors-from-data-frames-R.md +++ b/exercises/extracting-vectors-from-data-frames-R.md @@ -9,4 +9,4 @@ Using the Portal data `surveys` table ([download a copy](https://ndownloader.fig 1. Use `$` to extract the `weight` column into a vector 2. Use `[]` to extract the `month` column into a vector -3. Extract the `hindfoot_length` column into a vector and calculate the mean hindfoot length ignoring null values. \ No newline at end of file +3. Extract the `hindfoot_length` column into a vector using `pull()` and use this vector to calculate the mean hindfoot length ignoring null values \ No newline at end of file diff --git a/materials/converting-dataframes-vectors.md b/materials/converting-dataframes-vectors.md index 0f5571dce..554fb8268 100644 --- a/materials/converting-dataframes-vectors.md +++ b/materials/converting-dataframes-vectors.md @@ -62,6 +62,20 @@ species["species_id"] species[["species_id"]] ``` +* Finally, `dplyr` has a function called `pull()` + +```r +pull(species, species_id) +``` + +* This is typically used at the end a dplyr pipeline + +```r +species |> + filter(taxa == "Rodent") |> + pull(species_id) +``` + ### Combining vectors to make a data frame * We can also combine vectors to make a data frame