jim holtman wrote:
> Now take a look at what happens when you convert your dataframe to a matrix:
>
>   
>> x <- as.matrix(mydf)
>> str(x)
>>     
> ....
> It is a character matrix.
>
>   
This is a bit confusing (but deliberate; as.matrix.data.frame explicitly 
counts POSIXct as non-numeric):

 > mode(as.matrix(mydf)[1,1])
[1] "character"
 > mode(as.matrix(mydf[1,1]))
[1] "numeric"
 > mode(as.matrix(mydf[1,]))
[1] "character"
 > mode(as.matrix(mydf[,1]))
[1] "numeric"
 > mode(unlist(mydf[1,]))
[1] "numeric"
 > unlist(mydf[1,])
        X1         X2         X3         X4         X5         
X6         X7
1199835988 1199835988 1199835988 1199835988 1199835988 1199835988 
1199835988
        X8         X9        X10
1199835988 1199835988 1199835988


And hence also

 > sapply(mydf,max)
        X1         X2         X3         X4         X5         
X6         X7
1199835988 1199835988 1199835988 1199835988 1199835988 1199835988 
1199835988
        X8         X9        X10
1199835988 1199835988 1199835988

The ticket seems to be

 > do.call(c, lapply(mydf,max))
                       X1                        
X2                        X3
"2008-01-09 00:46:27 CET" "2008-01-09 00:46:27 CET" "2008-01-09 00:46:27 
CET"
                       X4                        
X5                        X6
"2008-01-09 00:46:27 CET" "2008-01-09 00:46:27 CET" "2008-01-09 00:46:27 
CET"
                       X7                        
X8                        X9
"2008-01-09 00:46:27 CET" "2008-01-09 00:46:27 CET" "2008-01-09 00:46:27 
CET"
                      X10
"2008-01-09 00:46:27 CET"

 > class(do.call(c,lapply(mydf,max)))
[1] "POSIXt"  "POSIXct"



-- 
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED])                  FAX: (+45) 35327907

______________________________________________
R-help@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.

Reply via email to