Generate a calendar in R

Asked

Viewed 159 times

2

I need to generate a calendar with working days in R, but only for the current year. I am using the package bizdays to generate the days, but do not know a way to select only the current year.

I tried to use it this way, but it didn’t work:

library(bizdays)
library(lubridate)

date <- as.Date("2020-01-01")
data <- seq(as.Date(date), length = 2, by = "+12 months")[2]

dias_uteis <- bizseq(from = date, to = data, cal = "Brazil/ANBIMA")
dias_uteis <- subset(dias_uteis, dias_uteis %in% year(date))
  • 2

    I don’t understand why the command dias_uteis <- bizseq(from = date, to = data, cal = "Brazil/ANBIMA") no longer solves this problem. For me, a sequence of 251 dates was created (see the result of length(dias_uteis)) which does not have several days, as can be seen in the result of tail(dias_uteis): "2020-12-23" "2020-12-24" "2020-12-28" "2020-12-29" "2020-12-30" "2020-12-31".

1 answer

3


To solve this problem you only need the function bizeq. This simplified code already solves your problem:

library(bizdays)
dias_uteis = bizseq("2020-01-01", "2021-01-01", "Brazil/ANBIMA")

I googled and there really are 251 working days in 2020.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.