Code
library(tidyverse)
library(lubridate)
::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE) knitr
Pavan Datta Abbineni
August 18, 2022
I decided to use the FedFundsRate dataset.
# 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`
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.
# 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
---
title: "Challenge 4"
author: "Pavan Datta Abbineni "
desription: "More data wrangling: pivoting"
date: "08/18/2022"
format:
html:
toc: true
code-fold: true
code-copy: true
code-tools: true
categories:
- challenge_4
---
```{r}
#| label: setup
#| warning: false
#| message: false
library(tidyverse)
library(lubridate)
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
```
I decided to use the FedFundsRate dataset.
```{r}
FedFundsRateData<-read_csv("_data/FedFundsRate.csv",
show_col_types = FALSE)
```
### Briefly describe the data
```{r visualize-dataset}
head(FedFundsRateData)
```
```{r dimensions}
dim(FedFundsRateData)
```
```{r column-names}
colnames(FedFundsRateData)
```
## 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.
```{r}
FedFundsRateData$Date <- str_c(FedFundsRateData$Year,"-",FedFundsRateData$Month,"-",FedFundsRateData$Day)%>%ymd()%>%as.Date()
```
```{r}
FedFundsRateData<-subset(FedFundsRateData,select=-c(1,2,3))
```
```{r}
FedFundsRateData<-pivot_longer(FedFundsRateData, 1:7, names_to = "Rates", values_to = "Value")
```
```{r}
head(FedFundsRateData)
```