Dplyr shrub volume data basics filter na (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. Remove rows with null values in the height column (using drop_na).
  2. Remove rows with null values in the height and width columns (using drop_na).
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. Remove rows with null values in the height column (using drop_na).
# A tibble: 13 × 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     1          3    2.7   1.5    2.2
 4     2          1    3     4.5    1.5
 5     2          2    3.1   3.1    4  
 6     2          3    2.5   2.8    3  
 7     3          1    1.9   1.8    4.5
 8     3          2    1.1   0.5    2.3
 9     3          3    3.5   2      7.5
10     4          1    2.9   2.7    3.2
11     4          2    4.5   4.8    6.5
12     4          3    1.2   1.8    2.7
13     5          2    1.8  NA      5.2
  1. Remove rows with null values in the height and width columns (using drop_na).
# A tibble: 12 × 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     1          3    2.7   1.5    2.2
 4     2          1    3     4.5    1.5
 5     2          2    3.1   3.1    4  
 6     2          3    2.5   2.8    3  
 7     3          1    1.9   1.8    4.5
 8     3          2    1.1   0.5    2.3
 9     3          3    3.5   2      7.5
10     4          1    2.9   2.7    3.2
11     4          2    4.5   4.8    6.5
12     4          3    1.2   1.8    2.7