Revision — Day 5, 09:30–10:30
acquire → wrangle → measure → see → model / map → report
Day 1 Day 1 Day 2 Day 2 Day 3 Day 4
Everything you ran this week sits on one of those six arrows. If you can name which arrow a task belongs to, you already know which function family to reach for.
readr::read_csv("data/pbs_cpi_raw.csv") |> janitor::clean_names()
haven::read_dta(here::here("data/hies/sec_1b_emp_income.dta")) # keeps labels
haven::read_sav(here::here("data/Fertility.sav"))
WDI::WDI(country = "PK", indicator = "SP.DYN.TFRT.IN")
pdftools::pdf_text("data/pdf/cpi_urban_groupwise.pdf") # PBS bulletins
rvest::read_html(url) |> rvest::html_table()The habit: here::here(), never setwd(). Then glimpse() before anything else.
pivot_longer() / pivot_wider() when the shape is wrong, not the data.
# survey-weighted, never raw means on complex surveys
srvyr::as_survey_design(df, ids = psu, strata = stratum, weights = wt) |>
srvyr::summarise(tfr = survey_mean(tfr, vartype = "ci"))
# CPI: splice across the 2007-08 -> 2015-16 base change, then YoY
cpi |> mutate(yoy = index / lag(index, 12) * 100 - 100, .by = group)Index numbers: Laspeyres, Paasche, Fisher, Törnqvist — and why the base year matters.
plotly::ggplotly() for hover · gganimate for time · gt/gtsummary for tables.
Always check the CRS and the join key before blaming the map.
One template, thirty outputs. This is the habit that pays for the week.
d4d.Rproj and using here::here()If the answer to any of these is “not sure”, the code is not finished.
Bring the one thing that is still broken in your own project.
d4d · Week in review