Skip to content

Commit

Permalink
Introduce pull for extracting vectors from data frames
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanwhite committed Sep 3, 2024
1 parent 9bc0247 commit 3de6a51
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion exercises/extracting-vectors-from-data-frames-R.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3. Extract the `hindfoot_length` column into a vector using `pull()` and use this vector to calculate the mean hindfoot length ignoring null values
14 changes: 14 additions & 0 deletions materials/converting-dataframes-vectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3de6a51

Please sign in to comment.