[R] its does not recognize POSIXct w/ both time and Date?

B. Bogart bbogart at sfu.ca
Wed Nov 7 20:14:38 CET 2007


Hello all,

Please disregard this thread, turns out I was not dealing with properly 
formated POSIXct data  actually. I'm writing only for the archives in 
case someone else has a similar problem.

I had loaded the file with read.table using colClasses to use POSIXct as 
the class for the first column. This did work, meaning class() returned 
the proper class, but only the date (not the time) was automatically 
interpreted.

This was easily solved by using "character" for the column class of the 
dates and using a separate time vector:

times = as.POSIXct(strptime(data$Time,format="%Y-%m-%d_%H:%M:%S"))

And now all is well.

Thanks for your help.
B. Bogart

Gabor Grothendieck wrote:
> On Nov 5, 2007 3:50 PM, B. Bogart <bbogart at sfu.ca> wrote:
>   
>> Hello all,
>>
>> I'm getting much further with my time-series work, but still getting
>> into some problems.
>>
>> I'm using POSIXct time format with both date and time.
>>
>> I'd like to use that in an its object but It seems its only processes
>> the date part of the POSIX time stamps:
>>
>> BMU_its_data <-  its(data[BMUindex,2-4],dates=data[BMUindex,1])
>> Error in `row.names<-.data.frame`(`*tmp*`, value = c("2007-10-31",
>> "2007-10-31",  :
>>
>>
>> The first column of the data is certainly correct, with both date and time:
>>
>>  > summary(data[BMUindex,1])
>>                     Min.                   1st Qu.
>> Median
>> "2007-10-31 07:00:00 UTC" "2007-11-01 07:00:00 UTC" "2007-11-03 07:00:00
>> UTC"
>>                     Mean                   3rd Qu.
>> Max.
>> "2007-11-02 21:44:12 UTC" "2007-11-04 07:00:00 UTC" "2007-11-05 08:00:00
>> UTC"
>>
>> Perhaps the functions used in its are unable to see the time field. I
>> noticed that using unique() on the same data gives me only 6 different
>> values, one for each day, with the times ignored.
>>
>> Is there any time format I can use in R (through its or zoo or fCalendar
>> or anything) that allows me to use tools such as unique() and so on and
>> have the times (not only dates) considered?
>>
>> I've chosen its because it seems to have pretty good ts specific
>> plotting stuff in there, but I'd be willing to use anything that allows
>> me to work with my POSIX dates down to the second. (or even msec)
>>
>>     
>
> Please provide reproducible examples as asked in last line on every
> message to r-help.
>
> Its unlikely that 'its' ignores date fields but perhaps this will get
> you going.
> Each of these gives the first value and its time for each value that occurs
> in the series:
>
>   
>> # its
>> library(its)
>> ii <- its(rep(1:2, 5), Sys.time() + 1:10)
>> ii[!duplicated(ii)]
>>     
> An object of class "its"
>          1
> 20071105 1
> 20071105 2
> Slot "dates":
> [1] "2007-11-05 16:03:09 Eastern Standard Time"
> [2] "2007-11-05 16:03:10 Eastern Standard Time"
>
>   
>> # zoo
>> library(zoo)
>> z <- zoo(rep(1:2, 5), Sys.time() + 1:10)
>> z[!duplicated(z)]
>>     
> 2007-11-05 16:03:10 2007-11-05 16:03:11
>                   1                   2
>



More information about the R-help mailing list