RohanAlexander / telling_stories

Telling Stories with Data
https://rohanalexander.github.io/telling_stories/
115 stars 77 forks source link

alberta_cod - Chapter 13 (skip=2 missing) #90

Closed tkanngiesser closed 12 months ago

tkanngiesser commented 1 year ago

Current Code:

  read_csv(
    "https://open.alberta.ca/dataset/03339dc5-fb51-4552-97c7-853688fc428d/resource/3e241965-fee3-400e-9652-07cfbf0c0bda/download/deaths-leading-causes.csv",
    col_types = cols(
      `Calendar Year` = col_integer(),
      Cause = col_character(),
      Ranking = col_integer(),
      `Total Deaths` = col_integer()
    )
  ) |>
  clean_names() |>
  add_count(cause) |>
  mutate(cause = str_trunc(cause, 30))

New names:Warning: The following named parsers don't match the column names: Calendar Year, Cause, Ranking, Total DeathsError in `add_count()`:
! Must group by variables found in `.data`.
✖ Column `cause` is not found.
Backtrace:
 1. dplyr::mutate(...)
 3. dplyr:::add_count.data.frame(...)

Updated Code with skip=2:


  read_csv(
    "https://open.alberta.ca/dataset/03339dc5-fb51-4552-97c7-853688fc428d/resource/3e241965-fee3-400e-9652-07cfbf0c0bda/download/deaths-leading-causes.csv", skip = 2,
    col_types = cols(
      `Calendar Year` = col_integer(),
      Cause = col_character(),
      Ranking = col_integer(),
      `Total Deaths` = col_integer()
    )
  ) |>
  clean_names() |>
  add_count(cause) |>
  mutate(cause = str_trunc(cause, 30))
RohanAlexander commented 12 months ago

Thank you very much for the comment. I had a look at the data - I think that they've updated the dataset format, so you're right that we need a skip now. Thanks very much for noticing! I'll updated and add an acknowledgement.