Challenge 10

Pull in Australian Marriage Data

australianMarriageTidy <- read_csv("challenge_datasets/australian_marriage_tidy.csv")
## Rows: 16 Columns: 4
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): territory, resp
## dbl (2): count, percent
## 
## ℹ 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.
View(australianMarriageTidy)

Create Function

summary<- function(data_vector) {
  summary <- list(
    Mean = mean(data_vector, na.rm = TRUE),
    Median = median(data_vector, na.rm = TRUE),
    Minimum = min(data_vector, na.rm = TRUE),
    Maximum = max(data_vector, na.rm = TRUE)
  )

  return(summary)
}

Apply function using Map within Purr

I am applying the function to the count and percent columns

australianMarriageTidySummary <- australianMarriageTidy %>% 
  select(count, percent) %>% 
  map(summary)

australianMarriageTidySummary
## $count
## $count$Mean
## [1] 793202.1
## 
## $count$Median
## [1] 524226
## 
## $count$Minimum
## [1] 31690
## 
## $count$Maximum
## [1] 2374362
## 
## 
## $percent
## $percent$Mean
## [1] 50
## 
## $percent$Median
## [1] 50
## 
## $percent$Minimum
## [1] 26
## 
## $percent$Maximum
## [1] 74