Financiële gegevens importeren en beheren in R
Joshua Ulrich
Quantitative Analyst & quantmod Co-Author and Maintainer
"2017-01-01" (begin)"2017-03-31" (eind)"2017-02-01" (midden)DGS10GDP# Aggreren naar kwartaal QGS10 <- apply.quarterly(DGS10, median, na.rm = TRUE)# Voeg kwartaalaggregaat samen met kwartaal-bbp QGS10_GDP <- merge(QGS10, GDP) QGS10_GDP
DGS10 GDP
2015-01-01 NA 17783.6
2015-03-31 1.97 NA
2015-04-01 NA 17998.3
2015-06-30 2.19 NA
2015-07-01 NA 18141.9
2015-09-30 2.20 NA
2015-10-01 NA 18222.8
2015-12-31 2.23 NA
yearmon() voor maanddatayearqtr() voor kwartaaldataas.Date("2017-01-01")
"2017-01-01"
as.yearmon("2017-01-01")
"Jan 2017"
as.yearqtr("2017-01-01")
"2017 Q1"
# Converteer beide indexen naar yearqtr
index(QGS10) <- as.yearqtr(index(QGS10))
index(GDP) <- as.yearqtr(index(GDP))
# Samenvoegen ‘werkt gewoon’
merge(QGS10, GDP)
DGS10 GDP
2015 Q1 1.97 17783.6
2015 Q2 2.19 17998.3
2015 Q3 2.20 18141.9
2015 Q4 2.23 18222.8
# Laatste waarneming achterwaarts vullen
QGS10_GDP_locb <- na.locf(QGS10_GDP, fromLast = TRUE)
# Subset op begin-van-periode-index
QGS10_GDP_first_period <- QGS10_GDP_locb[index(GDP)]
QGS10_GDP_first_period
DGS10 GDP
2015-01-01 1.97 17783.6
2015-04-01 2.19 17998.3
2015-07-01 2.20 18141.9
2015-10-01 2.23 18222.8
Financiële gegevens importeren en beheren in R