Dplyr penguins data basics filter (solution)

NoteExercise

If the file penguins.csv is not already in your working directory then download it into your working directory.

Load the data using read_csv() and use dplyr to complete the following tasks.

  1. Filter the data to include only penguins with flippers longer than 210 mm.
  2. Filter the data to include only penguins with flippers longer than 210 mm and body masses greater than 5000 g.
  3. Filter the data to include only penguins from the Dream or Torgersen islands.
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: 344 Columns: 8
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (3): species, island, sex
dbl (5): bill_length_mm, bill_depth_mm, flipper_length_mm, body_mass_g, year

ℹ 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 penguins with flippers longer than 210 mm.
# A tibble: 100 × 8
   species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
   <chr>   <chr>           <dbl>         <dbl>             <dbl>       <dbl>
 1 Gentoo  Biscoe           46.1          13.2               211        4500
 2 Gentoo  Biscoe           50            16.3               230        5700
 3 Gentoo  Biscoe           50            15.2               218        5700
 4 Gentoo  Biscoe           47.6          14.5               215        5400
 5 Gentoo  Biscoe           45.4          14.6               211        4800
 6 Gentoo  Biscoe           46.7          15.3               219        5200
 7 Gentoo  Biscoe           46.8          15.4               215        5150
 8 Gentoo  Biscoe           40.9          13.7               214        4650
 9 Gentoo  Biscoe           49            16.1               216        5550
10 Gentoo  Biscoe           45.5          13.7               214        4650
# ℹ 90 more rows
# ℹ 2 more variables: sex <chr>, year <dbl>
  1. Filter the data to include only penguins with flippers longer than 210 mm and body masses greater than 5000 g.
# A tibble: 58 × 8
   species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
   <chr>   <chr>           <dbl>         <dbl>             <dbl>       <dbl>
 1 Gentoo  Biscoe           50            16.3               230        5700
 2 Gentoo  Biscoe           50            15.2               218        5700
 3 Gentoo  Biscoe           47.6          14.5               215        5400
 4 Gentoo  Biscoe           46.7          15.3               219        5200
 5 Gentoo  Biscoe           46.8          15.4               215        5150
 6 Gentoo  Biscoe           49            16.1               216        5550
 7 Gentoo  Biscoe           48.4          14.6               213        5850
 8 Gentoo  Biscoe           49.3          15.7               217        5850
 9 Gentoo  Biscoe           49.2          15.2               221        6300
10 Gentoo  Biscoe           48.7          15.1               222        5350
# ℹ 48 more rows
# ℹ 2 more variables: sex <chr>, year <dbl>
  1. Filter the data to include only penguins from the Dream or Torgersen islands.
# A tibble: 176 × 8
   species island    bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
   <chr>   <chr>              <dbl>         <dbl>             <dbl>       <dbl>
 1 Adelie  Torgersen           39.1          18.7               181        3750
 2 Adelie  Torgersen           39.5          17.4               186        3800
 3 Adelie  Torgersen           40.3          18                 195        3250
 4 Adelie  Torgersen           NA            NA                  NA          NA
 5 Adelie  Torgersen           36.7          19.3               193        3450
 6 Adelie  Torgersen           39.3          20.6               190        3650
 7 Adelie  Torgersen           38.9          17.8               181        3625
 8 Adelie  Torgersen           39.2          19.6               195        4675
 9 Adelie  Torgersen           34.1          18.1               193        3475
10 Adelie  Torgersen           42            20.2               190        4250
# ℹ 166 more rows
# ℹ 2 more variables: sex <chr>, year <dbl>