[R] question about POSIXct conversion

Kosenkov Kirill Kosenkov.Kirill at nac.spb.ru
Thu Jun 5 20:37:14 CEST 2003


Thanks for reply, but when i am trying to

 > mt <- structure(mt, class=c("POSIXt", "POSIXct"))
 >
 > or
 >
 > mt + ISOdatetime(1970,1,1,0,0,0)

it seems that i loosing structre of matrix:

str(structure(mt, class=c("POSIXt", "POSIXct")))

 > `POSIXct', format: chr [1:44] "2003-06-05 12:10:00"...

instead of:
  num [1:11, 1:4] 1.05e

Both tricks coerces my matrix in "long" vector :((

Any other suggestions?

Prof Brian Ripley wrote:

> "character" is a mode
> 
> "POSIXct" is a class, but you want c("POSIXt", "POSIXct")
> 
> Try 
> 
> mt <- structure(mt, class=c("POSIXt", "POSIXct"))
> 
> or
> 
> mt + ISOdatetime(1970,1,1,0,0,0)
> 
> or several other such tricks.
> 
> On Thu, 5 Jun 2003, Kosenkov Kirill wrote:
> 
> 
>>Hello!
>>
>>I am trying to compute minimal time on some data like this:
>>mt<-tapply(mrsh$time1,list(mrsh$var1,mrsh$var2),min):
>>
>>	      a 		b
>>145         1054800600         1054789800
>>340         1054804500         1054794600
>>349         1054820400         1054792800
>>55          1054800600         1054789200
>>57          1054814100         1054791000
>>78          1054822200         1054790400
>>843         1054807200         1054795800
>>864         1054813800         1054790700
>>92          1054789500         1054790100
>>940         1054800600         1054795800
>>971         1054783800         1054796700
>>
>>where time1 is POSIXct object.
>>
>>str(mt) tells me, that mt has mode 'numeric' NOT POSIXct
>>
>>When i am trying to set: mode(mt)<-'POSIXct' i get a message:
>>
>>Don't know how to convert `structure(c(1054800600, 1054804500, ' 
>>to class "POSIXct"
>>
>>When i am trying to do: mode(mt)<-'character' everything is ok.
>>
>>I've tried: class(mt)<-'POSIXct' but matrix structure seems to be 
>>lost.
>>
>>How to convert the numeric result of tapply on POSIXct object 
>>(with 'min') to POSIXct again???
>>
>>Thanks!
>>
>>______________________________________________
>>R-help at stat.math.ethz.ch mailing list
>>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>>
> 
>




More information about the R-help mailing list