library(palmerpenguins) # load data set package
data("penguins") # load data set

head(penguins, 5) # return first five rows of data
## # A tibble: 5 × 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
## # ℹ 2 more variables: sex <fct>, year <int>
summary(penguins) # summary statistics of data frame
##       species          island    bill_length_mm  bill_depth_mm  
##  Adelie   :152   Biscoe   :168   Min.   :32.10   Min.   :13.10  
##  Chinstrap: 68   Dream    :124   1st Qu.:39.23   1st Qu.:15.60  
##  Gentoo   :124   Torgersen: 52   Median :44.45   Median :17.30  
##                                  Mean   :43.92   Mean   :17.15  
##                                  3rd Qu.:48.50   3rd Qu.:18.70  
##                                  Max.   :59.60   Max.   :21.50  
##                                  NA's   :2       NA's   :2      
##  flipper_length_mm  body_mass_g       sex           year     
##  Min.   :172.0     Min.   :2700   female:165   Min.   :2007  
##  1st Qu.:190.0     1st Qu.:3550   male  :168   1st Qu.:2007  
##  Median :197.0     Median :4050   NA's  : 11   Median :2008  
##  Mean   :200.9     Mean   :4202                Mean   :2008  
##  3rd Qu.:213.0     3rd Qu.:4750                3rd Qu.:2009  
##  Max.   :231.0     Max.   :6300                Max.   :2009  
##  NA's   :2         NA's   :2
# subset with the flipper length of penguins on Dream Island
subset <- subset(penguins, island == "Dream")$flipper_length_mm

subset_mean <- round(mean(subset, na.rm = TRUE), 2) # subset mean rounded two decimal places

print(paste("The mean flipper length in Dream Island is", subset_mean, "mm"))
## [1] "The mean flipper length in Dream Island is 193.07 mm"
subset_median <- round(median(subset, na.rm = TRUE), 2) # subset median rounded two decimal places

print(paste("The median flipper length in Dream Island is", subset_median, "mm"))
## [1] "The median flipper length in Dream Island is 193 mm"
subset_var <- round(var(subset, na.rm = TRUE), 2) # subset variance rounded two decimal places

print(paste("The variance for flipper length in Dream Island is", subset_var))
## [1] "The variance for flipper length in Dream Island is 56.36"
subset_sd <- round(sd(subset, na.rm = TRUE), 2) # subset standard deviation rounded two decimal places

print(paste("The standard deviation for flipper length in Dream Island is", subset_sd), 2)
## [1] "The standard deviation for flipper length in Dream Island is 7.51"