[R] question about POSIXct conversion

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jun 5 20:03:55 CEST 2003


"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
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list