I want to create a vector of dates, for which I created a simple loop which added the dates i am interested in to a vector. However, for some reason it turns it into a list.
library(timeDate)
listOfHolidays <- c()
for (year in c(getRmetricsOptions("currentYear") ,getRmetricsOptions("currentYear") +1)) {
listOfHolidays <- c(listOfHolidays,GoodFriday(year),EasterMonday(year))}
print(listOfHolidays)
[[1]]
GMT
[1] [2020-04-10]
[[2]]
GMT
[1] [2020-04-13]
[[3]]
GMT
[1] [2021-04-02]
[[4]]
GMT
[1] [2021-04-05]
The standard approach to turn a list into a vector is to use unlist()
for me, however this does not work here for some reason. The only working way for me was this convoluted version here.
tmp <- as.Date(as.data.frame(t(as.data.frame(listOfHolidays)))$V1)
So my questions are quite basic. 1. Why is it suddenly a list. 2. How to I change it into a plain vector in a more elegant way.