DACSS 601: Data Science Fundamentals - FALL 2022
  • Fall 2022 Posts
  • Contributors
  • DACSS

Challenge 4 Solutions

  • Course information
    • Overview
    • Instructional Team
    • Course Schedule
  • Weekly materials
    • Fall 2022 posts
    • final posts

On this page

  • Read in data
    • Briefly describe the data
  • Tidy Data (as needed)
  • Identify variables that need to be mutated

Challenge 4 Solutions

Author

Tejaswini Ketineni

Published

November 7, 2022

##Challenge_4

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

Read in data

library(readr)
FedFundsRate <- read_csv("_data/FedFundsRate.csv")

Briefly describe the data

To see sample columns in the data set we do a head

head(FedFundsRate)
# 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`
colnames(FedFundsRate)
 [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"              
dim(FedFundsRate)
[1] 904  10
print(summarytools::dfSummary(FedFundsRate,
                        varnumbers = FALSE,
                        plain.ascii  = FALSE, 
                        style        = "grid", 
                        graph.magnif = 0.70, 
                        valid.col    = FALSE),
      method = 'render',
      table.classes = 'table-condensed')

Data Frame Summary

FedFundsRate

Dimensions: 904 x 10
Duplicates: 0
Variable Stats / Values Freqs (% of Valid) Graph Missing
Year [numeric]
Mean (sd) : 1986.7 (17.2)
min ≤ med ≤ max:
1954 ≤ 1987.5 ≤ 2017
IQR (CV) : 28 (0)
64 distinct values 0 (0.0%)
Month [numeric]
Mean (sd) : 6.6 (3.5)
min ≤ med ≤ max:
1 ≤ 7 ≤ 12
IQR (CV) : 6 (0.5)
12 distinct values 0 (0.0%)
Day [numeric]
Mean (sd) : 3.6 (6.8)
min ≤ med ≤ max:
1 ≤ 1 ≤ 31
IQR (CV) : 0 (1.9)
29 distinct values 0 (0.0%)
Federal Funds Target Rate [numeric]
Mean (sd) : 5.7 (2.6)
min ≤ med ≤ max:
1 ≤ 5.5 ≤ 11.5
IQR (CV) : 4 (0.5)
63 distinct values 442 (48.9%)
Federal Funds Upper Target [numeric]
Mean (sd) : 0.3 (0.1)
min ≤ med ≤ max:
0.2 ≤ 0.2 ≤ 1
IQR (CV) : 0 (0.5)
4 distinct values 801 (88.6%)
Federal Funds Lower Target [numeric]
Mean (sd) : 0.1 (0.1)
min ≤ med ≤ max:
0 ≤ 0 ≤ 0.8
IQR (CV) : 0 (2.4)
4 distinct values 801 (88.6%)
Effective Federal Funds Rate [numeric]
Mean (sd) : 4.9 (3.6)
min ≤ med ≤ max:
0.1 ≤ 4.7 ≤ 19.1
IQR (CV) : 4.2 (0.7)
466 distinct values 152 (16.8%)
Real GDP (Percent Change) [numeric]
Mean (sd) : 3.1 (3.6)
min ≤ med ≤ max:
-10 ≤ 3.1 ≤ 16.5
IQR (CV) : 3.5 (1.1)
113 distinct values 654 (72.3%)
Unemployment Rate [numeric]
Mean (sd) : 6 (1.6)
min ≤ med ≤ max:
3.4 ≤ 5.7 ≤ 10.8
IQR (CV) : 2.1 (0.3)
71 distinct values 152 (16.8%)
Inflation Rate [numeric]
Mean (sd) : 3.7 (2.6)
min ≤ med ≤ max:
0.6 ≤ 2.8 ≤ 13.6
IQR (CV) : 2.7 (0.7)
106 distinct values 194 (21.5%)

Generated by summarytools 1.0.1 (R version 4.2.1)
2022-12-21

Tidy Data (as needed)

Is your data already tidy, or is there work to be done? Be sure to anticipate your end result to provide a sanity check, and document your work here.

we see that there are many na’s in the data, so we replace all of them by 0’s

FedFundsRate<- FedFundsRate %>% replace_na(list(`Federal Funds Target Rate`=0,`Federal Funds Lower Target`=0,`Inflation Rate`=0, `Federal Funds Upper Target`=0,`Real GDP (Percent Change)` =0, `Unemployment Rate` =0,`Effective Federal Funds Rate`=0))

Identify variables that need to be mutated

I have observed that year month and day are separated, So it’s optimal to have the date formatted.

FedFundsRate$Date <- str_c(FedFundsRate$Year,"-",FedFundsRate$Month,"-",FedFundsRate$Day)%>%ymd()%>%as.Date()
FedFundsRate$Date
  [1] "1954-07-01" "1954-08-01" "1954-09-01" "1954-10-01" "1954-11-01"
  [6] "1954-12-01" "1955-01-01" "1955-02-01" "1955-03-01" "1955-04-01"
 [11] "1955-05-01" "1955-06-01" "1955-07-01" "1955-08-01" "1955-09-01"
 [16] "1955-10-01" "1955-11-01" "1955-12-01" "1956-01-01" "1956-02-01"
 [21] "1956-03-01" "1956-04-01" "1956-05-01" "1956-06-01" "1956-07-01"
 [26] "1956-08-01" "1956-09-01" "1956-10-01" "1956-11-01" "1956-12-01"
 [31] "1957-01-01" "1957-02-01" "1957-03-01" "1957-04-01" "1957-05-01"
 [36] "1957-06-01" "1957-07-01" "1957-08-01" "1957-09-01" "1957-10-01"
 [41] "1957-11-01" "1957-12-01" "1958-01-01" "1958-02-01" "1958-03-01"
 [46] "1958-04-01" "1958-05-01" "1958-06-01" "1958-07-01" "1958-08-01"
 [51] "1958-09-01" "1958-10-01" "1958-11-01" "1958-12-01" "1959-01-01"
 [56] "1959-02-01" "1959-03-01" "1959-04-01" "1959-05-01" "1959-06-01"
 [61] "1959-07-01" "1959-08-01" "1959-09-01" "1959-10-01" "1959-11-01"
 [66] "1959-12-01" "1960-01-01" "1960-02-01" "1960-03-01" "1960-04-01"
 [71] "1960-05-01" "1960-06-01" "1960-07-01" "1960-08-01" "1960-09-01"
 [76] "1960-10-01" "1960-11-01" "1960-12-01" "1961-01-01" "1961-02-01"
 [81] "1961-03-01" "1961-04-01" "1961-05-01" "1961-06-01" "1961-07-01"
 [86] "1961-08-01" "1961-09-01" "1961-10-01" "1961-11-01" "1961-12-01"
 [91] "1962-01-01" "1962-02-01" "1962-03-01" "1962-04-01" "1962-05-01"
 [96] "1962-06-01" "1962-07-01" "1962-08-01" "1962-09-01" "1962-10-01"
[101] "1962-11-01" "1962-12-01" "1963-01-01" "1963-02-01" "1963-03-01"
[106] "1963-04-01" "1963-05-01" "1963-06-01" "1963-07-01" "1963-08-01"
[111] "1963-09-01" "1963-10-01" "1963-11-01" "1963-12-01" "1964-01-01"
[116] "1964-02-01" "1964-03-01" "1964-04-01" "1964-05-01" "1964-06-01"
[121] "1964-07-01" "1964-08-01" "1964-09-01" "1964-10-01" "1964-11-01"
[126] "1964-12-01" "1965-01-01" "1965-02-01" "1965-03-01" "1965-04-01"
[131] "1965-05-01" "1965-06-01" "1965-07-01" "1965-08-01" "1965-09-01"
[136] "1965-10-01" "1965-11-01" "1965-12-01" "1966-01-01" "1966-02-01"
[141] "1966-03-01" "1966-04-01" "1966-05-01" "1966-06-01" "1966-07-01"
[146] "1966-08-01" "1966-09-01" "1966-10-01" "1966-11-01" "1966-12-01"
[151] "1967-01-01" "1967-02-01" "1967-03-01" "1967-04-01" "1967-05-01"
[156] "1967-06-01" "1967-07-01" "1967-08-01" "1967-09-01" "1967-10-01"
[161] "1967-11-01" "1967-12-01" "1968-01-01" "1968-02-01" "1968-03-01"
[166] "1968-04-01" "1968-05-01" "1968-06-01" "1968-07-01" "1968-08-01"
[171] "1968-09-01" "1968-10-01" "1968-11-01" "1968-12-01" "1969-01-01"
[176] "1969-02-01" "1969-03-01" "1969-04-01" "1969-05-01" "1969-06-01"
[181] "1969-07-01" "1969-08-01" "1969-09-01" "1969-10-01" "1969-11-01"
[186] "1969-12-01" "1970-01-01" "1970-02-01" "1970-03-01" "1970-04-01"
[191] "1970-05-01" "1970-06-01" "1970-07-01" "1970-08-01" "1970-09-01"
[196] "1970-10-01" "1970-11-01" "1970-12-01" "1971-01-01" "1971-02-01"
[201] "1971-03-01" "1971-04-01" "1971-05-01" "1971-06-01" "1971-07-01"
[206] "1971-08-01" "1971-09-01" "1971-10-01" "1971-11-01" "1971-12-01"
[211] "1972-01-01" "1972-02-01" "1972-03-01" "1972-04-01" "1972-05-01"
[216] "1972-06-01" "1972-07-01" "1972-08-01" "1972-09-01" "1972-10-01"
[221] "1972-11-01" "1972-12-01" "1973-01-01" "1973-02-01" "1973-03-01"
[226] "1973-04-01" "1973-05-01" "1973-06-01" "1973-07-01" "1973-08-01"
[231] "1973-09-01" "1973-10-01" "1973-11-01" "1973-12-01" "1974-01-01"
[236] "1974-02-01" "1974-03-01" "1974-04-01" "1974-05-01" "1974-06-01"
[241] "1974-07-01" "1974-08-01" "1974-09-01" "1974-10-01" "1974-11-01"
[246] "1974-12-01" "1975-01-01" "1975-02-01" "1975-03-01" "1975-04-01"
[251] "1975-05-01" "1975-06-01" "1975-07-01" "1975-08-01" "1975-09-01"
[256] "1975-10-01" "1975-11-01" "1975-12-01" "1976-01-01" "1976-02-01"
[261] "1976-03-01" "1976-04-01" "1976-05-01" "1976-06-01" "1976-07-01"
[266] "1976-08-01" "1976-09-01" "1976-10-01" "1976-11-01" "1976-12-01"
[271] "1977-01-01" "1977-02-01" "1977-03-01" "1977-04-01" "1977-05-01"
[276] "1977-06-01" "1977-07-01" "1977-08-01" "1977-09-01" "1977-10-01"
[281] "1977-11-01" "1977-12-01" "1978-01-01" "1978-02-01" "1978-03-01"
[286] "1978-04-01" "1978-05-01" "1978-06-01" "1978-07-01" "1978-08-01"
[291] "1978-09-01" "1978-10-01" "1978-11-01" "1978-12-01" "1979-01-01"
[296] "1979-02-01" "1979-03-01" "1979-04-01" "1979-05-01" "1979-06-01"
[301] "1979-07-01" "1979-08-01" "1979-09-01" "1979-10-01" "1979-11-01"
[306] "1979-12-01" "1980-01-01" "1980-02-01" "1980-03-01" "1980-04-01"
[311] "1980-05-01" "1980-06-01" "1980-07-01" "1980-08-01" "1980-09-01"
[316] "1980-10-01" "1980-11-01" "1980-12-01" "1981-01-01" "1981-02-01"
[321] "1981-03-01" "1981-04-01" "1981-05-01" "1981-06-01" "1981-07-01"
[326] "1981-08-01" "1981-09-01" "1981-10-01" "1981-11-01" "1981-12-01"
[331] "1982-01-01" "1982-02-01" "1982-03-01" "1982-04-01" "1982-05-01"
[336] "1982-06-01" "1982-07-01" "1982-08-01" "1982-09-01" "1982-09-27"
[341] "1982-10-01" "1982-10-07" "1982-11-01" "1982-11-19" "1982-12-01"
[346] "1982-12-14" "1983-01-01" "1983-02-01" "1983-03-01" "1983-03-31"
[351] "1983-04-01" "1983-05-01" "1983-05-25" "1983-06-01" "1983-06-24"
[356] "1983-07-01" "1983-07-14" "1983-07-20" "1983-08-01" "1983-08-11"
[361] "1983-08-17" "1983-09-01" "1983-09-15" "1983-10-01" "1983-11-01"
[366] "1983-12-01" "1984-01-01" "1984-02-01" "1984-03-01" "1984-03-29"
[371] "1984-04-01" "1984-05-01" "1984-06-01" "1984-07-01" "1984-07-05"
[376] "1984-07-19" "1984-08-01" "1984-08-09" "1984-09-01" "1984-09-20"
[381] "1984-09-27" "1984-10-01" "1984-10-11" "1984-10-18" "1984-11-01"
[386] "1984-11-08" "1984-11-23" "1984-12-01" "1984-12-06" "1984-12-19"
[391] "1984-12-24" "1985-01-01" "1985-01-24" "1985-02-01" "1985-02-14"
[396] "1985-03-01" "1985-03-28" "1985-04-01" "1985-04-25" "1985-05-01"
[401] "1985-05-20" "1985-06-01" "1985-07-01" "1985-07-11" "1985-08-01"
[406] "1985-08-21" "1985-09-01" "1985-09-06" "1985-10-01" "1985-11-01"
[411] "1985-12-01" "1985-12-18" "1986-01-01" "1986-02-01" "1986-03-01"
[416] "1986-03-07" "1986-04-01" "1986-04-02" "1986-04-21" "1986-05-01"
[421] "1986-05-22" "1986-06-01" "1986-06-05" "1986-07-01" "1986-07-11"
[426] "1986-08-01" "1986-08-21" "1986-09-01" "1986-10-01" "1986-11-01"
[431] "1986-12-01" "1987-01-01" "1987-01-05" "1987-02-01" "1987-03-01"
[436] "1987-04-01" "1987-04-30" "1987-05-01" "1987-05-22" "1987-06-01"
[441] "1987-07-01" "1987-07-02" "1987-08-01" "1987-08-27" "1987-09-01"
[446] "1987-09-03" "1987-09-04" "1987-09-24" "1987-10-01" "1987-11-01"
[451] "1987-11-04" "1987-12-01" "1988-01-01" "1988-01-28" "1988-02-01"
[456] "1988-02-11" "1988-03-01" "1988-03-30" "1988-04-01" "1988-05-01"
[461] "1988-05-09" "1988-05-25" "1988-06-01" "1988-06-22" "1988-07-01"
[466] "1988-07-19" "1988-08-01" "1988-08-08" "1988-08-09" "1988-09-01"
[471] "1988-10-01" "1988-11-01" "1988-11-17" "1988-11-22" "1988-12-01"
[476] "1988-12-15" "1989-01-01" "1989-01-05" "1989-02-01" "1989-02-09"
[481] "1989-02-14" "1989-02-24" "1989-03-01" "1989-04-01" "1989-05-01"
[486] "1989-05-17" "1989-06-01" "1989-06-06" "1989-07-01" "1989-07-07"
[491] "1989-07-27" "1989-08-01" "1989-09-01" "1989-10-01" "1989-10-19"
[496] "1989-11-01" "1989-11-06" "1989-12-01" "1989-12-20" "1990-01-01"
[501] "1990-02-01" "1990-03-01" "1990-04-01" "1990-05-01" "1990-06-01"
[506] "1990-07-01" "1990-07-13" "1990-08-01" "1990-09-01" "1990-10-01"
[511] "1990-10-29" "1990-11-01" "1990-11-14" "1990-12-01" "1990-12-07"
[516] "1990-12-19" "1991-01-01" "1991-01-09" "1991-02-01" "1991-03-01"
[521] "1991-03-08" "1991-04-01" "1991-04-30" "1991-05-01" "1991-06-01"
[526] "1991-07-01" "1991-08-01" "1991-08-06" "1991-09-01" "1991-09-13"
[531] "1991-10-01" "1991-10-31" "1991-11-01" "1991-11-06" "1991-12-01"
[536] "1991-12-06" "1991-12-20" "1992-01-01" "1992-02-01" "1992-03-01"
[541] "1992-04-01" "1992-04-09" "1992-05-01" "1992-06-01" "1992-07-01"
[546] "1992-07-02" "1992-08-01" "1992-09-01" "1992-09-04" "1992-10-01"
[551] "1992-11-01" "1992-12-01" "1993-01-01" "1993-02-01" "1993-03-01"
[556] "1993-04-01" "1993-05-01" "1993-06-01" "1993-07-01" "1993-08-01"
[561] "1993-09-01" "1993-10-01" "1993-11-01" "1993-12-01" "1994-01-01"
[566] "1994-02-01" "1994-02-04" "1994-03-01" "1994-03-22" "1994-04-01"
[571] "1994-04-18" "1994-05-01" "1994-05-17" "1994-06-01" "1994-07-01"
[576] "1994-08-01" "1994-08-16" "1994-09-01" "1994-10-01" "1994-11-01"
[581] "1994-11-15" "1994-12-01" "1995-01-01" "1995-02-01" "1995-03-01"
[586] "1995-04-01" "1995-05-01" "1995-06-01" "1995-07-01" "1995-07-06"
[591] "1995-08-01" "1995-09-01" "1995-10-01" "1995-11-01" "1995-12-01"
[596] "1995-12-19" "1996-01-01" "1996-01-31" "1996-02-01" "1996-03-01"
[601] "1996-04-01" "1996-05-01" "1996-06-01" "1996-07-01" "1996-08-01"
[606] "1996-09-01" "1996-10-01" "1996-11-01" "1996-12-01" "1997-01-01"
[611] "1997-02-01" "1997-03-01" "1997-03-25" "1997-04-01" "1997-05-01"
[616] "1997-06-01" "1997-07-01" "1997-08-01" "1997-09-01" "1997-10-01"
[621] "1997-11-01" "1997-12-01" "1998-01-01" "1998-02-01" "1998-03-01"
[626] "1998-04-01" "1998-05-01" "1998-06-01" "1998-07-01" "1998-08-01"
[631] "1998-09-01" "1998-09-29" "1998-10-01" "1998-10-15" "1998-11-01"
[636] "1998-11-17" "1998-12-01" "1999-01-01" "1999-02-01" "1999-03-01"
[641] "1999-04-01" "1999-05-01" "1999-06-01" "1999-06-30" "1999-07-01"
[646] "1999-08-01" "1999-08-24" "1999-09-01" "1999-10-01" "1999-11-01"
[651] "1999-11-16" "1999-12-01" "2000-01-01" "2000-02-01" "2000-02-02"
[656] "2000-03-01" "2000-03-21" "2000-04-01" "2000-05-01" "2000-05-16"
[661] "2000-06-01" "2000-07-01" "2000-08-01" "2000-09-01" "2000-10-01"
[666] "2000-11-01" "2000-12-01" "2001-01-01" "2001-01-03" "2001-01-31"
[671] "2001-02-01" "2001-03-01" "2001-03-20" "2001-04-01" "2001-04-18"
[676] "2001-05-01" "2001-05-15" "2001-06-01" "2001-06-27" "2001-07-01"
[681] "2001-08-01" "2001-08-21" "2001-09-01" "2001-09-17" "2001-10-01"
[686] "2001-10-02" "2001-11-01" "2001-11-06" "2001-12-01" "2001-12-11"
[691] "2002-01-01" "2002-02-01" "2002-03-01" "2002-04-01" "2002-05-01"
[696] "2002-06-01" "2002-07-01" "2002-08-01" "2002-09-01" "2002-10-01"
[701] "2002-11-01" "2002-11-06" "2002-12-01" "2003-01-01" "2003-02-01"
[706] "2003-03-01" "2003-04-01" "2003-05-01" "2003-06-01" "2003-06-25"
[711] "2003-07-01" "2003-08-01" "2003-09-01" "2003-10-01" "2003-11-01"
[716] "2003-12-01" "2004-01-01" "2004-02-01" "2004-03-01" "2004-04-01"
[721] "2004-05-01" "2004-06-01" "2004-06-30" "2004-07-01" "2004-08-01"
[726] "2004-08-10" "2004-09-01" "2004-09-21" "2004-10-01" "2004-11-01"
[731] "2004-11-10" "2004-12-01" "2004-12-14" "2005-01-01" "2005-02-01"
[736] "2005-02-02" "2005-03-01" "2005-03-22" "2005-04-01" "2005-05-01"
[741] "2005-05-03" "2005-06-01" "2005-06-30" "2005-07-01" "2005-08-01"
[746] "2005-08-09" "2005-09-01" "2005-09-20" "2005-10-01" "2005-11-01"
[751] "2005-12-01" "2005-12-13" "2006-01-01" "2006-01-31" "2006-02-01"
[756] "2006-03-01" "2006-03-28" "2006-04-01" "2006-05-01" "2006-05-10"
[761] "2006-06-01" "2006-06-29" "2006-07-01" "2006-08-01" "2006-09-01"
[766] "2006-10-01" "2006-11-01" "2006-12-01" "2007-01-01" "2007-02-01"
[771] "2007-03-01" "2007-04-01" "2007-05-01" "2007-06-01" "2007-07-01"
[776] "2007-08-01" "2007-09-01" "2007-09-18" "2007-10-01" "2007-10-31"
[781] "2007-11-01" "2007-12-01" "2007-12-11" "2008-01-01" "2008-01-22"
[786] "2008-01-30" "2008-02-01" "2008-03-01" "2008-03-18" "2008-04-01"
[791] "2008-04-30" "2008-05-01" "2008-06-01" "2008-07-01" "2008-08-01"
[796] "2008-09-01" "2008-10-01" "2008-10-08" "2008-10-29" "2008-11-01"
[801] "2008-12-01" "2008-12-16" "2009-01-01" "2009-02-01" "2009-03-01"
[806] "2009-04-01" "2009-05-01" "2009-06-01" "2009-07-01" "2009-08-01"
[811] "2009-09-01" "2009-10-01" "2009-11-01" "2009-12-01" "2010-01-01"
[816] "2010-02-01" "2010-03-01" "2010-04-01" "2010-05-01" "2010-06-01"
[821] "2010-07-01" "2010-08-01" "2010-09-01" "2010-10-01" "2010-11-01"
[826] "2010-12-01" "2011-01-01" "2011-02-01" "2011-03-01" "2011-04-01"
[831] "2011-05-01" "2011-06-01" "2011-07-01" "2011-08-01" "2011-09-01"
[836] "2011-10-01" "2011-11-01" "2011-12-01" "2012-01-01" "2012-02-01"
[841] "2012-03-01" "2012-04-01" "2012-05-01" "2012-06-01" "2012-07-01"
[846] "2012-08-01" "2012-09-01" "2012-10-01" "2012-11-01" "2012-12-01"
[851] "2013-01-01" "2013-02-01" "2013-03-01" "2013-04-01" "2013-05-01"
[856] "2013-06-01" "2013-07-01" "2013-08-01" "2013-09-01" "2013-10-01"
[861] "2013-11-01" "2013-12-01" "2014-01-01" "2014-02-01" "2014-03-01"
[866] "2014-04-01" "2014-05-01" "2014-06-01" "2014-07-01" "2014-08-01"
[871] "2014-09-01" "2014-10-01" "2014-11-01" "2014-12-01" "2015-01-01"
[876] "2015-02-01" "2015-03-01" "2015-04-01" "2015-05-01" "2015-06-01"
[881] "2015-07-01" "2015-08-01" "2015-09-01" "2015-10-01" "2015-11-01"
[886] "2015-12-01" "2015-12-16" "2016-01-01" "2016-02-01" "2016-03-01"
[891] "2016-04-01" "2016-05-01" "2016-06-01" "2016-07-01" "2016-08-01"
[896] "2016-09-01" "2016-10-01" "2016-11-01" "2016-12-01" "2016-12-14"
[901] "2017-01-01" "2017-02-01" "2017-03-01" "2017-03-16"
feds <- FedFundsRate %>% 
  pivot_longer(cols = c( "Federal Funds Target Rate","Inflation Rate","Federal Funds Lower Target",
                         "Federal Funds Upper Target","Effective Federal Funds Rate","Unemployment Rate","Real GDP (Percent Change)"),
               names_to = "names",
               values_to = "value",
               values_drop_na = TRUE)

feds
# A tibble: 6,328 × 6
    Year Month   Day Date       names                        value
   <dbl> <dbl> <dbl> <date>     <chr>                        <dbl>
 1  1954     7     1 1954-07-01 Federal Funds Target Rate      0  
 2  1954     7     1 1954-07-01 Inflation Rate                 0  
 3  1954     7     1 1954-07-01 Federal Funds Lower Target     0  
 4  1954     7     1 1954-07-01 Federal Funds Upper Target     0  
 5  1954     7     1 1954-07-01 Effective Federal Funds Rate   0.8
 6  1954     7     1 1954-07-01 Unemployment Rate              5.8
 7  1954     7     1 1954-07-01 Real GDP (Percent Change)      4.6
 8  1954     8     1 1954-08-01 Federal Funds Target Rate      0  
 9  1954     8     1 1954-08-01 Inflation Rate                 0  
10  1954     8     1 1954-08-01 Federal Funds Lower Target     0  
# … with 6,318 more rows

deleting the first three columns

feds<-subset(feds,select=-c(1,2,3))
head(feds)
# A tibble: 6 × 3
  Date       names                        value
  <date>     <chr>                        <dbl>
1 1954-07-01 Federal Funds Target Rate      0  
2 1954-07-01 Inflation Rate                 0  
3 1954-07-01 Federal Funds Lower Target     0  
4 1954-07-01 Federal Funds Upper Target     0  
5 1954-07-01 Effective Federal Funds Rate   0.8
6 1954-07-01 Unemployment Rate              5.8

The data is now tidy enough to work

Source Code
---
title: "Challenge 4 Solutions"
author: "Tejaswini Ketineni"
date: "11/07/2022"
format:
  html:
    toc: true
    code-copy: true
    code-tools: true
---
##Challenge_4


```{r}
#| label: setup
#| warning: false
#| message: false

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


## Read in data

```{r}
library(readr)
FedFundsRate <- read_csv("_data/FedFundsRate.csv")

```

### Briefly describe the data

To see sample columns in the data set we do a head

```{r}
head(FedFundsRate)
```
```{r}
colnames(FedFundsRate)
```

```{r}
dim(FedFundsRate)

```

```{r}
print(summarytools::dfSummary(FedFundsRate,
                        varnumbers = FALSE,
                        plain.ascii  = FALSE, 
                        style        = "grid", 
                        graph.magnif = 0.70, 
                        valid.col    = FALSE),
      method = 'render',
      table.classes = 'table-condensed')

```

## Tidy Data (as needed)

Is your data already tidy, or is there work to be done? Be sure to anticipate your end result to provide a sanity check, and document your work here.

we see that there are many na's in the data, so we replace all of them by 0's

```{r}
FedFundsRate<- FedFundsRate %>% replace_na(list(`Federal Funds Target Rate`=0,`Federal Funds Lower Target`=0,`Inflation Rate`=0, `Federal Funds Upper Target`=0,`Real GDP (Percent Change)` =0, `Unemployment Rate` =0,`Effective Federal Funds Rate`=0))
```



## Identify variables that need to be mutated

I have observed that year month and day are separated, So it's optimal to have the date formatted.


```{r}
FedFundsRate$Date <- str_c(FedFundsRate$Year,"-",FedFundsRate$Month,"-",FedFundsRate$Day)%>%ymd()%>%as.Date()
```

```{r}
FedFundsRate$Date
```

```{r}
feds <- FedFundsRate %>% 
  pivot_longer(cols = c( "Federal Funds Target Rate","Inflation Rate","Federal Funds Lower Target",
                         "Federal Funds Upper Target","Effective Federal Funds Rate","Unemployment Rate","Real GDP (Percent Change)"),
               names_to = "names",
               values_to = "value",
               values_drop_na = TRUE)

feds

```
deleting the first three columns
```{r}
feds<-subset(feds,select=-c(1,2,3))
```

```{r}
head(feds)
```

The data is now tidy enough to work