Dplyr shrub volume data basics filter (solution)

NoteExercise

Dr. Morales is interested in studying the factors controlling the size and carbon storage of shrubs. She has conducted an experiment looking at the effect of three different treatments on shrub volume at four different locations. She has placed the data file on the web for you to download:

If the file shrub-volume-data.csv is not already in your working directory (it probably is if you’re taking this class using Posit Cloud) then download it into your working directory.

Get familiar with the data by importing it using read_csv() and use dplyr to complete the following tasks.

  1. Filter the data to include only plants with heights greater than 5 (using filter).
  2. Filter the data to include only plants with heights greater than 4 and widths greater than 2 (using , or & to include two conditions).
  3. Filter the data to include only plants from Experiment 1 or Experiment 3 (using | for “or”).
CautionOutput solution

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
Rows: 15 Columns: 5
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (5): site, experiment, length, width, height

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
  1. Filter the data to include only plants with heights greater than 5 (using filter).
# A tibble: 5 × 5
   site experiment length width height
  <dbl>      <dbl>  <dbl> <dbl>  <dbl>
1     1          1    2.2   1.3    9.6
2     1          2    2.1   2.2    7.6
3     3          3    3.5   2      7.5
4     4          2    4.5   4.8    6.5
5     5          2    1.8  NA      5.2
  1. Filter the data to include only plants with heights greater than 4 and widths greater than 2.
# A tibble: 2 × 5
   site experiment length width height
  <dbl>      <dbl>  <dbl> <dbl>  <dbl>
1     1          2    2.1   2.2    7.6
2     4          2    4.5   4.8    6.5
  1. Filter the data to include only plants from Experiment 1 or Experiment 3.
# A tibble: 10 × 5
    site experiment length width height
   <dbl>      <dbl>  <dbl> <dbl>  <dbl>
 1     1          1    2.2   1.3    9.6
 2     1          3    2.7   1.5    2.2
 3     2          1    3     4.5    1.5
 4     2          3    2.5   2.8    3  
 5     3          1    1.9   1.8    4.5
 6     3          3    3.5   2      7.5
 7     4          1    2.9   2.7    3.2
 8     4          3    1.2   1.8    2.7
 9     5          1    2.6   0.8   NA  
10     5          3    3.1   2.2   NA