Daily Exercise 05

ESS 330 - Quantitative Reasoning

# Attach the `palmerspenguins` package
  library(palmerpenguins)

# 1. Examine at the dataset using the ?Help page
  #?penguins

# 2. what is the class of the penguins dataset?
  class(penguins)
[1] "tbl_df"     "tbl"        "data.frame"
# 3. what is the structure of the penguins dataset?
  str(penguins)
tibble [344 × 8] (S3: tbl_df/tbl/data.frame)
 $ species          : Factor w/ 3 levels "Adelie","Chinstrap",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ island           : Factor w/ 3 levels "Biscoe","Dream",..: 3 3 3 3 3 3 3 3 3 3 ...
 $ bill_length_mm   : num [1:344] 39.1 39.5 40.3 NA 36.7 39.3 38.9 39.2 34.1 42 ...
 $ bill_depth_mm    : num [1:344] 18.7 17.4 18 NA 19.3 20.6 17.8 19.6 18.1 20.2 ...
 $ flipper_length_mm: int [1:344] 181 186 195 NA 193 190 181 195 193 190 ...
 $ body_mass_g      : int [1:344] 3750 3800 3250 NA 3450 3650 3625 4675 3475 4250 ...
 $ sex              : Factor w/ 2 levels "female","male": 2 1 1 NA 1 2 1 2 NA NA ...
 $ year             : int [1:344] 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 ...
# 4. what are the dimensions of the penguins dataset?
  #Rows
  dim(penguins)[1]
[1] 344
  #Columns
  dim(penguins)[2]
[1] 8
# 5. what are the column names of the penguins dataset?
  colnames(penguins)
[1] "species"           "island"            "bill_length_mm"   
[4] "bill_depth_mm"     "flipper_length_mm" "body_mass_g"      
[7] "sex"               "year"             
# 6. what type of data is `flipper_length_mm` and `Island`?
  #flipper_length_mm: 
  class(penguins$flipper_length_mm)
[1] "integer"
  #Island: 
  class(penguins$island)
[1] "factor"
# 7. what is the mean flipper length of the penguins?
  mean(penguins$flipper_length_mm, na.rm = TRUE)
[1] 200.9152
# 8. what is the standard deviation of flipper length in the penguins?
  sd (penguins$flipper_length_mm, na.rm = TRUE)
[1] 14.06171
# 9. what is the median body mass of the penguins?
  median(penguins$body_mass_g, na.rm = TRUE)
[1] 4050
# 10. what is the Island of the 100th penguin?
  penguins$island[100]
[1] Dream
Levels: Biscoe Dream Torgersen