[R] 'Date' elements within a matrix

Gabor Grothendieck ggrothendieck at gmail.com
Sun Mar 13 18:02:18 CET 2011


On Sun, Mar 13, 2011 at 11:46 AM, Bogaso Christofer
<bogaso.christofer at gmail.com> wrote:
> Thanks everyone for clarifying my query. However I was wondering why that
> Date character is not preserved within a matrix? Why R forcefully changes
> that to numeric? I am especially concerned because as per the definition of
> the matrix, each element needs to be of same class. Is there any other
> example other than Date class which R forcefully changes to some simpler
> class if it placed within a matrix?
>

Actually it is possible although there will be some limitations in how
certain methods treat it:

> dd <- seq(as.Date("2011-01-01"), as.Date("2011-01-09"), by = "day")
> dim(dd) <- c(3, 3)
> dd
[1] "2011-01-01" "2011-01-02" "2011-01-03" "2011-01-04" "2011-01-05"
[6] "2011-01-06" "2011-01-07" "2011-01-08" "2011-01-09"
> dd[1,1]
[1] "2011-01-01"
> dd[1,]
[1] "2011-01-01" "2011-01-04" "2011-01-07"





-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list