library(tidyverse)
library(janitor)
Practice Day 1
This is the notebook fellows will work through on the first day of the Center for Health Journalism Hands-On R course.
You will be using daily weather summaries that have been downloaded from Climate Data Online. The explanations use Texas, but there are files for Arkansas, California, New York and North Carolina for practice.
Goals
Our goals are to:
- Import our data.
- Check all the column data types.
- Add some new columns based on the date.
- Recode some values in our data.
- Remove some unnecessary variables/columns.
- Export our cleaned data.
Setup
Add the entire code block for libraries.
Import
Follow the directions in the lesson to import the Texas data, starting with adding a new code block:
OYO: Import a different state
Go through all the steps above, but with different a different state.
Peeking at data
Use head, tail, glimpse and summary to look at the Texas data.
Look at the top of your data:
Look at 8 lines of the bottom of your data:
Use glimpse to see all your columns:
Use summary to learn about all your variables:
OYO: Peek at your state’s data
Use those same functions above to look at your state’s data.
Create or change data
Create year, month values based on the date. This is a multi-step process:
OYO: Make date parts
Make the same date parts, but with your own state data:
Recoding values
Use distinct so you can see the station names:
Use mutate to recode
Use recode to create a new column of short city names:
Now check your results using distinct on name
and city
:
OYO: Recode your cities
Make similar short names, but for your state.
Select
Create a new version of your data with only the columns you need, in the order you want them:
OYO: Select your cols
Go through the same process as above, but with your own state data.
Export
Write the file out as “rds” to the data-processed
folder:
OYO: Export your state
Write your data to the data-processed
folder. Make sure you use a name for your state.
Checking your notebooks
Clear out your notebook and rerun all the code. Render the HTML page.