[R] timeDate & business day

Michael Toews mwtoews at sfu.ca
Tue Mar 13 01:12:20 CET 2007


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



More information about the R-help mailing list