Re: [R] retaining "POSIXct" formatting when using apply(muff, FUN=MAX) on POSIXct dataframe?

From: jim holtman <jholtman_at_gmail.com>
Date: Tue, 8 Jan 2008 18:35:32 -0500

It all depends on what you are doing. Take a look at 'apply'; it says:

If X is not an array but has a dimension attribute, apply attempts to coerce it to an array via as.matrix if it is two-dimensional (e.g., data frames) or via as.array.

Now take a look at what happens when you convert your dataframe to a matrix:

> x <- as.matrix(mydf)
> str(x)

 chr [1:2, 1:10] "2008-01-08 23:29:25" "2008-01-08 23:29:25" "2008-01-08 23:29:25" ...

It is a character matrix.

On Jan 8, 2008 12:28 PM, Thomas Pujol <thomas.pujol_at_yahoo.com> wrote:
> How do I retain "POSIXct" formatting when using apply, with FUN=max?
>
> #example:
> mydata <- rep(Sys.time(), 10)
> mydf <- data.frame(matrix(data=mydata, nrow=2, ncol=length(mydata) ) )
> for(i in seq(mydf))class(mydf[[i]]) <- class(mydata)
> str(mydf)
> maxdates <- apply(mydf,2,max,na.rm=T)
> str(maxdates)
>
> #Why is the formattign now "chr", and not "POSIXct"?
> #Is there a good way to retin "POSIXct" formatting?
>
>
>
> ---------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 08 Jan 2008 - 23:38:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 Jan 2008 - 04:30:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive