I have a daily time series and have two questions to get some help with. Firs,t I have dates in simple numeric values. e.g. ymd [1] 20050104 20050105 20050106 20050107 20050110 20050111 20050113 20050114 [9] 20050118 20050120 20050121 20050124 20050125 20050126 20050127 20050128 [17] 20050201 20050202 20050203 20050204 Now, I'd like to compute statistics, e.g. acf, by business days. So, I try to convert it into timeDate class. But, when I try to change date format, this is what I am getting:> tt = timeDate('20050101',format=c('%Y%m%d'),FinCenter='GMT') > unclass(tt)list() attr(,"Data") [1] "2005-01-01" attr(,"Dim") [1] 1 attr(,"format") [1] "%Y-%m-%d" attr(,"FinCenter") [1] "GMT" Somehow, I can't change the format to 'yyyymmdd' (e.g. 19950401) Also, I was wondering if there is a function similar to 'timeRelative' in Splus. So that actually I can add or substract n business days to and from timeDate. Or, is there a simpler way to compute statistics for daily time series? ( based on business days ) Thanks a lot [[alternative HTML version deleted]]
Those numbers look like ... well, numbers. You want characters! Try converting the integer to a character before trying to do a string parse, e.g.: ymd.int <- c(20050104, 20050105, 20050106, 20050107, 20050110, 20050111, 20050113, 20050114) ymd <- as.Date(as.character(ymd.int),"%Y%m%d") As far as the other functions you are looking at ("timeDate", "timeRelative") -- I've never seen these, so I'm guessing they are S-PLUS. In R, you can use "diff" or "difftime" (which works with "Date" and "POSIXlt"-or Date-Time classes) , e.g.: diff(ymd) diff(ymd,2) diff(ymd,3) or do some arithmetic: difftime(ymd[1],ymd[4]) difftime(ymd[1],ymd[4],unit="weeks") Hopefully this is helpful to you! +mt
Reasonably Related Threads
- Can I create a timeDate object using only year and week of the year values?
- timeSeries Date Warning messages: Set timezone to GMT!
- holidayNYSE missing some
- Problem using RMySQL and fCalendar
- [R-SIG-Finance] FinCenter in timeSeries with "merge", "cbind" and "rbind"