[R] timeDate & business day

Young Cho young.stat at gmail.com
Tue Mar 13 05:07:55 CET 2007


Thanks so Michael! If you know of a tutorial or introductory document  
about timeDate manipulation or time series manipulation in R, can you  
share it? It is hard to find by googling... I'd very appreciate any  
advice.

Young.

On Mar 12, 2007, at 9:00 PM, Michael Toews wrote:

>
>> [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.
> What happened in the beginning is that I had to parse the character  
> into a Date-Time class ("Date", in this case as you correctly  
> pointed out). POSIX is a kind of standard that (mainly Unix)  
> computers use date formatters, such as %Y for a 4-digit year, and  
> others. They are all listed in great detail in "?strptime" (which  
> means "string parse time"). In this case the input parsing format  
> pattern was "%Y%m%d". There were no spaces in-between each number.
>
> When that class prints out, the default format is ISO 8601 ( see  
> http://en.wikipedia.org/wiki/ISO_8601 ). When R prints the class  
> "Date" to your screen, it decides to format it ISO 8601-style for  
> you. If you want to see if differently, you can try:
>
> format(ymd,"%Y/%d/%m")
>
> The date is actually stored internally as an ordinal, somewhat like  
> how MS Excel dates work. You can see how it works internally:
>
> str(ymd)
>
> Hopefully I've demystified some of this .. any other questions?
> +mt



More information about the R-help mailing list