library(tidyverse)
library(ggplot2)
library(lubridate)
library(readxl)
::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE) knitr
Challenge 9 Solution
challenge_9
Susannah Reed Poland
Creating a function
Create a function that reads in and cleans a dataset
I chose to create a function that changes a column of year and quarter characters to dates, and removes the old column.
#create a function called "read_debt", f is the file name and by default is false
<-function(f){
read_debt#read in the data file
<-read_excel(f)%>%
d#change the "year and quarter" to a date format
mutate(date_orig = parse_date_time(`Year and Quarter`, orders="yq"))%>%
#remove the old column
select(-`Year and Quarter`)
return(d)
}
Now we can apply this to the “Debt in Trillions” dataset:
#apply function
<-read_debt("_data/debt_in_trillions.xlsx")
debt_date
#check it out!
debt_date
Et voila!