Reputation: 11
I have a set of one year finacial data. The data is collected in working days. Is there any way in R to assign to each data point a date given that the first data point was collected for eaxmple on juanari the 3th.
Upvotes: 1
Views: 213
Reputation: 263342
The timeDate package offers functions to extract business days in whatever financial center you happen to favor (there are almost 500 such financialcenters in their classification).
Upvotes: 1
Reputation: 179428
You need to take two steps to get to a solution:
seq.Date
wday
to calculate the day of the week and remove all days with value 1 (Sunday) and 7 (Saturday)The code and results:
startdate <- as.Date("2011-01-03")
dates <- seq(startdate, by="1 day", length.out=15)
dates[wday(dates) != 1 & wday(dates) != 7]
[1] "2011-01-03" "2011-01-04" "2011-01-05" "2011-01-06" "2011-01-07"
[6] "2011-01-10" "2011-01-11" "2011-01-12" "2011-01-13" "2011-01-14"
[11] "2011-01-17"
PS. You will have two keep a separate lists of holidays in your region and remove these from the list.
Upvotes: 2