[R] A question about POSIXct

Michael Sumner mdsumner at utas.edu.au
Fri May 4 01:49:32 CEST 2007


Jacques Wagnor wrote:
> A follow-up question:  The example in ?attr uses a character string of
> "dim."  Besides "dim" and "times," what other character strings are
> available or can be used?
Ah, it's not limited to those. Any character string would do (guru 
caveats aside).  
I suspect my narrow answer to your question might lead you astray, 
perhaps you should cut to the chase and ask how to get your data file 
into which  function in evir . . .

Cheers, Mike.
>
> On 5/3/07, Michael Sumner <mdsumner at utas.edu.au> wrote:
>>
>> Hello,
>>
>> It seems that "danish" is a numeric vector with attributes attached -
>> the attribute vector is POSIXct and is the same length as danish.
>>
>> You can create this from a data frame like this:
>>
>> x <- data.frame(Date = ISOdate(2007, 5, 1:10), Value = rnorm(10))
>> str(x)
>> 'data.frame':   10 obs. of  2 variables:
>> $ Date :'POSIXct', format: chr  "2007-05-01 12:00:00" "2007-05-02
>> 12:00:00" "2007-05-03 12:00:00" "2007-05-04 12:00:00" ...
>> $ Value: num   1.891  0.741 -0.368  1.701 -0.660 ...
>>
>> xx <- x$Value
>> attr(xx, "times") <- x$Date
>> str(xx)
>> atomic [1:10]  0.0414 -0.7124 -1.2976  0.3101  0.4343 ...
>> - attr(*, "times")='POSIXct', format: chr [1:10] "2007-05-01 12:00:00"
>> "2007-05-02 12:00:00" "2007-05-03 12:00:00" "2007-05-04 12:00:00" ...
>>
>>
>> HTH
>>
>> Cheers, Mike.



More information about the R-help mailing list