[R] timeDate & business day

AA aa2007r at gmail.com
Tue Mar 13 02:55:55 CET 2007


Hi Michael,

Thanks for your reply.
I am experiencing the same issue as Young
The following code gives:
ymd.int <- c(20050104, 20050105, 20050106, 20050107, 20050110, 20050111,
+ 20050113, 20050114)
> ymd.int
[1] 20050104 20050105 20050106 20050107 20050110 20050111 20050113 20050114
> ymd <- as.Date(as.character(ymd.int),"%Y%m%d")
> ymd
[1] "2005-01-04" "2005-01-05" "2005-01-06" "2005-01-07" "2005-01-10"
[6] "2005-01-11" "2005-01-13" "2005-01-14"
> class(ymd)
[1] "Date"

While the variable ymd is actually of class Date, the format is not yyyymmdd 
but
yyyy-mm-dd as one can see in the previous example.
As Young, I do not see what I am missing here.
Any hint would be appreciated.

AA.




----- Original Message ----- 
From: "Michael Toews" <mwtoews at sfu.ca>
To: <r-help at stat.math.ethz.ch>
Sent: Monday, March 12, 2007 8:12 PM
Subject: [R] timeDate & business day


> 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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list