challenge_4
Author

Pavan Datta Abbineni

Published

August 18, 2022

Code
library(tidyverse)
library(lubridate)
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)

I decided to use the FedFundsRate dataset.

Code
FedFundsRateData<-read_csv("_data/FedFundsRate.csv",
                        show_col_types = FALSE)

Briefly describe the data

Code
head(FedFundsRateData)
# A tibble: 6 × 10
   Year Month   Day Federal Fu…¹ Feder…² Feder…³ Effec…⁴ Real …⁵ Unemp…⁶ Infla…⁷
  <dbl> <dbl> <dbl>        <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
1  1954     7     1           NA      NA      NA    0.8      4.6     5.8      NA
2  1954     8     1           NA      NA      NA    1.22    NA       6        NA
3  1954     9     1           NA      NA      NA    1.06    NA       6.1      NA
4  1954    10     1           NA      NA      NA    0.85     8       5.7      NA
5  1954    11     1           NA      NA      NA    0.83    NA       5.3      NA
6  1954    12     1           NA      NA      NA    1.28    NA       5        NA
# … with abbreviated variable names ¹​`Federal Funds Target Rate`,
#   ²​`Federal Funds Upper Target`, ³​`Federal Funds Lower Target`,
#   ⁴​`Effective Federal Funds Rate`, ⁵​`Real GDP (Percent Change)`,
#   ⁶​`Unemployment Rate`, ⁷​`Inflation Rate`
Code
dim(FedFundsRateData)
[1] 904  10
Code
colnames(FedFundsRateData)
 [1] "Year"                         "Month"                       
 [3] "Day"                          "Federal Funds Target Rate"   
 [5] "Federal Funds Upper Target"   "Federal Funds Lower Target"  
 [7] "Effective Federal Funds Rate" "Real GDP (Percent Change)"   
 [9] "Unemployment Rate"            "Inflation Rate"              

Tidy Data (as needed)

In tidy data each variable has its own column, every observation its own row and each value its own cell.

The current dataset is not tidy. We need to modify the Year, Month and Day column into a single date column. Lets create a new column named date which is the addition of the three column names stated above.

Code
FedFundsRateData$Date <- str_c(FedFundsRateData$Year,"-",FedFundsRateData$Month,"-",FedFundsRateData$Day)%>%ymd()%>%as.Date()
Code
FedFundsRateData<-subset(FedFundsRateData,select=-c(1,2,3))
Code
FedFundsRateData<-pivot_longer(FedFundsRateData, 1:7, names_to = "Rates", values_to = "Value")
Code
head(FedFundsRateData)
# A tibble: 6 × 3
  Date       Rates                        Value
  <date>     <chr>                        <dbl>
1 1954-07-01 Federal Funds Target Rate     NA  
2 1954-07-01 Federal Funds Upper Target    NA  
3 1954-07-01 Federal Funds Lower Target    NA  
4 1954-07-01 Effective Federal Funds Rate   0.8
5 1954-07-01 Real GDP (Percent Change)      4.6
6 1954-07-01 Unemployment Rate              5.8