Here are some practice problems to explore the penguins data set. First we need to load the penguin data set.
library("palmerpenguins")penguins
# A tibble: 344 × 8
species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
<fct> <fct> <dbl> <dbl> <int> <int>
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
# ℹ 334 more rows
# ℹ 2 more variables: sex <fct>, year <int>
What are the mean and standard deviation of bill length of the penguins?
# create a variable that contains only the column for bill lengthbillLength<-penguins$bill_length_mm# mean mean(billLength, na.rm=TRUE)
[1] 43.92193
# standard deviationsd(billLength, na.rm=TRUE)
[1] 5.459584
What are the mean and standard deviation of the body mass of the penguins?
# create a variable that contains only the column for body massbodyMass<-penguins$body_mass_g# meanmean(bodyMass, na.rm=TRUE)
[1] 4201.754
# standard deviationsd(bodyMass, na.rm =TRUE)
[1] 801.9545
What is the mean and median flipper length of the penguins?
# create a variable that contains only the column for flipper lengthflipperLength<-penguins$flipper_length_mm# meanmean(flipperLength, na.rm=TRUE)
[1] 200.9152
# medianmedian(flipperLength, na.rm=TRUE)
[1] 197
How long are the largest flippers in this data set? How long is the shortest? (Hint: google how to find the minimum and maximum values in a vector). You can use the same variable that you created in 3!
What is the range of bill depths of penguins? (Range is the maximum value - minimum value)
billDepth<-penguins$bill_depth_mm# deepest bill depthdeepest<-max(billDepth, na.rm=TRUE)# shallowest bill depthshallowest<-min(billDepth, na.rm=TRUE)# range of bill depthrange<-deepest - shallowestrange
[1] 8.4
How many species of penguins are in this data set (hint: there is a function to find distinct values in a vector)? List them using comments.
# get unique valuesspecies<-unique(penguins$species)# count themlength(species)
[1] 3
Find the value for the longest bill in the data set. Assign it to the variable longestBill.