[R] rownames, colnames, and date and time
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Jul 3 13:44:12 CEST 2006
Note that if you are really trying to represent time series using
rownames as the time variable then you might consider using
the zoo or its packages (or ts class if they are regular) instead.
library(zoo)
mymat<-matrix(1:4,nrow=2,ncol=2)
mydates<-as.POSIXct(c("2001-1-24","2005-12-25"))
z <- zoo(mymat, mydates)
z
On 7/3/06, Brandt, T. (Tobias) <TobiasBr at taquanta.com> wrote:
> Hi all
>
> I was wondering whether there has ever been an update on the rownames and
> colnames behaviour as described by Eric below?
>
> I still get the same behaviour, exactly as described by Eric, on my WinXP
> installation of R-2.3.0. I also posted a message to r-help on Friday but
> looking through the online archives it seems to have not made it to the
> list. I would agree with Eric that a consistent use of the typecast would
> be a reasonable solution.
>
> Any comments?
>
> Tobias Brandt
> Quantitative Analyst
> Taquanta Asset Managers
> Nedbank Clock Tower
> Victoria & Alfred Waterfront, Cape Town 8001
> Tel : +27 (0) 21 416 6602
> Fax : +27 (0) 21 416 9945
> Email : TobiasBr at Taquanta.com <mailto:TobiasBr at Taquanta.com>
>
>
> >-----Original Message-----
> >From: r-help-bounces at stat.math.ethz.ch
> >[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Erich Neuwirth
> >Sent: 21 March 2006 01:31 PM
> >To: R-help at stat.math.ethz.ch
> >Cc: Christian Prinoth
> >Subject: [R] rownames, colnames, and date and time
> >
> >I noticed something surprising (in R 2.2.1 on WinXP) According
> >to the documentation, rownames and colnames are character vectors.
> >Assigning a vector of class POSIXct or POSIXlt as rownames or
> >colnames therefore is not strictly according to the rules.
> >In some cases, R performs a reasonable typecast, but in some
> >other cases where the same typecast also would be possible, it
> >does not.
> >
> >Assigning a vector of class POSIXct to the rownames or names
> >of a dataframe creates a reasonable string representation of
> >the dates (and possibly times).
> >Assigning such a vector to the rownames or colnames of a
> >matrix produces rownames or colnames consisting of the integer
> >representation of the date-time value.
> >Trying to assign a vector of class POSIXlt in all cases
> >(dataframes and matrices, rownames, colnames, names) produces an error.
> >
> >Demonstration code is given below.
> >
> >This is somewhat inconsistent.
> >Perhaps a reasonable solution could be that the typecast used
> >for POSIXct and dataframes is used in all the other cases also.
> >
> >Code:
> >
> >mymat<-matrix(1:4,nrow=2,ncol=2)
> >mydf<-data.frame(mymat)
> >mydates<-as.POSIXct(c("2001-1-24","2005-12-25"))
> >
> >rownames(mydf)<-mydates
> >names(mydf)<-mydates
> >rownames(mymat)<-mydates
> >colnames(mymat)<-mydates
> >
> >print(deparse(mydates))
> >print(deparse(rownames(mydf)))
> >print(deparse(names(mydf)))
> >print(deparse(rownames(mymat)))
> >print(deparse(colnames(mymat)))
> >
> >mydates1<-as.POSIXlt(mydates)
> >
> ># the following lines will not work and
> ># produce errors
> >
> >rownames(mydf)<-mydates1
> >names(mydf)<-mydates1
> >rownames(mymat)<-mydates1
> >colnames(mymat)<-mydates1
> >
> >
> >--
> >Erich Neuwirth
> >Institute for Scientific Computing and
> >Didactic Center for Computer Science
> >University of Vienna
> >phone: +43-1-4277-39464 fax: +43-1-4277-39459
> >
> >______________________________________________
> >R-help at stat.math.ethz.ch mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide!
> >http://www.R-project.org/posting-guide.html
> >
>
> ********************
> Nedbank Limited Reg No 1951/000009/06. The following link displays the names of the Nedbank Board of Directors and Company Secretary. [ http://www.nedbank.co.za/terms/DirectorsNedbank.htm ]
> This email is confidential and is intended for the addressee only. The following link will take you to Nedbank's legal notice. [ http://www.nedbank.co.za/terms/EmailDisclaimer.htm ]
> ********************
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list