Penguins vectors and data frames (solution)

NoteExercise

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

Load penguins_no_na.csv into R using read_csv().

Copy the following vectors into R:

region = c("Anvers", "Anvers", "Anvers")
island = c("Biscoe", "Dream", "Torgersen")
area = c(26.2, 42.0, 6.7)
  1. Use $ to extract the flipper length column into a vector
  2. Use [] to extract the body mass column into a vector
  3. Extract the bill length column into a vector using pull() and use this vector to determine the maximum bill length
  4. Using the vectors you copied into R, create a new data frame named islands with region, island, and area columns
  5. Create a combined table including the information from both the penguins and the islands tables together
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: 333 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. Use $ to extract the flipper length column into a vector
  [1] 181 186 195 193 190 181 195 182 191 198 185 195 197 184 194 174 180 189
 [19] 185 180 187 183 187 172 180 178 178 188 184 195 196 190 180 181 184 182
 [37] 195 186 196 185 190 182 190 191 186 188 190 200 187 191 186 193 181 194
 [55] 185 195 185 192 184 192 195 188 190 198 190 190 196 197 190 195 191 184
 [73] 187 195 189 196 187 193 191 194 190 189 189 190 202 205 185 186 187 208
 [91] 190 196 178 192 192 203 183 190 193 184 199 190 181 197 198 191 193 197
[109] 191 196 188 199 189 189 187 198 176 202 186 199 191 195 191 210 190 197
[127] 193 199 187 190 191 200 185 193 193 187 188 190 192 185 190 184 195 193
[145] 187 201 211 230 210 218 215 210 211 219 209 215 214 216 214 213 210 217
[163] 210 221 209 222 218 215 213 215 215 215 215 210 220 222 209 207 230 220
[181] 220 213 219 208 208 208 225 210 216 222 217 210 225 213 215 210 220 210
[199] 225 217 220 208 220 208 224 208 221 214 231 219 230 229 220 223 216 221
[217] 221 217 216 230 209 220 215 223 212 221 212 224 212 228 218 218 212 230
[235] 218 228 212 224 214 226 216 222 203 225 219 228 215 228 215 210 219 208
[253] 209 216 229 213 230 217 230 222 214 215 222 212 213 192 196 193 188 197
[271] 198 178 197 195 198 193 194 185 201 190 201 197 181 190 195 181 191 187
[289] 193 195 197 200 200 191 205 187 201 187 203 195 199 195 210 192 205 210
[307] 187 196 196 196 201 190 212 187 198 199 201 193 203 187 197 191 203 202
[325] 194 206 189 195 207 202 193 210 198
  1. Use [] to extract the body mass column into a vector
  [1] 3750 3800 3250 3450 3650 3625 4675 3200 3800 4400 3700 3450 4500 3325 4200
 [16] 3400 3600 3800 3950 3800 3800 3550 3200 3150 3950 3250 3900 3300 3900 3325
 [31] 4150 3950 3550 3300 4650 3150 3900 3100 4400 3000 4600 3425 3450 4150 3500
 [46] 4300 3450 4050 2900 3700 3550 3800 2850 3750 3150 4400 3600 4050 2850 3950
 [61] 3350 4100 3050 4450 3600 3900 3550 4150 3700 4250 3700 3900 3550 4000 3200
 [76] 4700 3800 4200 3350 3550 3800 3500 3950 3600 3550 4300 3400 4450 3300 4300
 [91] 3700 4350 2900 4100 3725 4725 3075 4250 2925 3550 3750 3900 3175 4775 3825
[106] 4600 3200 4275 3900 4075 2900 3775 3350 3325 3150 3500 3450 3875 3050 4000
[121] 3275 4300 3050 4000 3325 3500 3500 4475 3425 3900 3175 3975 3400 4250 3400
[136] 3475 3050 3725 3000 3650 4250 3475 3450 3750 3700 4000 4500 5700 4450 5700
[151] 5400 4550 4800 5200 4400 5150 4650 5550 4650 5850 4200 5850 4150 6300 4800
[166] 5350 5700 5000 4400 5050 5000 5100 5650 4600 5550 5250 4700 5050 6050 5150
[181] 5400 4950 5250 4350 5350 3950 5700 4300 4750 5550 4900 4200 5400 5100 5300
[196] 4850 5300 4400 5000 4900 5050 4300 5000 4450 5550 4200 5300 4400 5650 4700
[211] 5700 5800 4700 5550 4750 5000 5100 5200 4700 5800 4600 6000 4750 5950 4625
[226] 5450 4725 5350 4750 5600 4600 5300 4875 5550 4950 5400 4750 5650 4850 5200
[241] 4925 4875 4625 5250 4850 5600 4975 5500 5500 4700 5500 4575 5500 5000 5950
[256] 4650 5500 4375 5850 6000 4925 4850 5750 5200 5400 3500 3900 3650 3525 3725
[271] 3950 3250 3750 4150 3700 3800 3775 3700 4050 3575 4050 3300 3700 3450 4400
[286] 3600 3400 2900 3800 3300 4150 3400 3800 3700 4550 3200 4300 3350 4100 3600
[301] 3900 3850 4800 2700 4500 3950 3650 3550 3500 3675 4450 3400 4300 3250 3675
[316] 3325 3950 3600 4050 3350 3450 3250 4050 3800 3525 3950 3650 3650 4000 3400
[331] 3775 4100 3775
  1. Extract the bill length column into a vector using pull() and use this vector to determine the maximum bill length
[1] 59.6
  1. Using the vectors you copied into R, create a new data frame named islands with region, island, and area columns
  region    island area
1 Anvers    Biscoe 26.2
2 Anvers     Dream 42.0
3 Anvers Torgersen  6.7
  1. Create a combined table including the information from both the penguins and the islands tables together
# A tibble: 333 × 10
   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           36.7          19.3               193        3450
 5 Adelie  Torgersen           39.3          20.6               190        3650
 6 Adelie  Torgersen           38.9          17.8               181        3625
 7 Adelie  Torgersen           39.2          19.6               195        4675
 8 Adelie  Torgersen           41.1          17.6               182        3200
 9 Adelie  Torgersen           38.6          21.2               191        3800
10 Adelie  Torgersen           34.6          21.1               198        4400
# ℹ 323 more rows
# ℹ 4 more variables: sex <chr>, year <dbl>, region <chr>, area <dbl>