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.
Asked
Active
Viewed 205 times
2 Answers
2
You need to take two steps to get to a solution:
- Create a sequence of dates using
seq.Date
- Use
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.

Andrie
- 176,377
- 47
- 447
- 496
1
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).

IRTFM
- 258,963
- 21
- 364
- 487