Hi everybody, I need your precious help for, I think, a simple request, but I do not manage to solve this. When I use a "table" function with dates in the rows, the rows are coerced to number after the table function. So I need to transform the row names into date format. But I do not manage. Therefore, for an example, I manage to write this : datetest<-"06/01/2001" datetest<-as.Date(datetest,"%d/%m/%Y") datetest<-as.numeric(datetest) to get 11328. But I do not obtain the inverse tranformation : datetest<-as.Date(datetest,"%d/%m/%Y") How do we get this please ? Thanks a lot for your solution. Pierre. [[alternative HTML version deleted]]
Try this: library(zoo) as.Date(11328) See the Help Desk article in R News 4/1 for more on dates. On 7/11/06, pierre clauss <pierreclauss at yahoo.fr> wrote:> Hi everybody, > I need your precious help for, I think, a simple request, but I do not manage to solve this. > > When I use a "table" function with dates in the rows, the rows are coerced to number after the table function. > > So I need to transform the row names into date format. But I do not manage. > > Therefore, for an example, I manage to write this : > > datetest<-"06/01/2001" > datetest<-as.Date(datetest,"%d/%m/%Y") > datetest<-as.numeric(datetest) > > to get 11328. > > But I do not obtain the inverse tranformation : > > datetest<-as.Date(datetest,"%d/%m/%Y") > > How do we get this please ? > > Thanks a lot for your solution. > Pierre. > > > > [[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 >
I moved this to R-devel because I am wondering why the base package does
not allow you to convert from numeric to Date. Could we not have
something like this?
as.Date.numeric <- function(x, epoch="1970-01-01", ...) {
if (!is.character(epoch) || length(epoch) != 1)
stop("invalid epoch")
as.Date(epoch, ...) + x
}
Martyn
On Tue, 2006-07-11 at 12:58 -0400, Gabor Grothendieck
wrote:> Try this:
>
> library(zoo)
> as.Date(11328)
>
> See the Help Desk article in R News 4/1 for more on dates.
>
>
> On 7/11/06, pierre clauss <pierreclauss at yahoo.fr> wrote:
> > Hi everybody,
> > I need your precious help for, I think, a simple request, but I do not
manage to solve this.
> >
> > When I use a "table" function with dates in the rows, the
rows are coerced to number after the table function.
> >
> > So I need to transform the row names into date format. But I do not
manage.
> >
> > Therefore, for an example, I manage to write this :
> >
> > datetest<-"06/01/2001"
> > datetest<-as.Date(datetest,"%d/%m/%Y")
> > datetest<-as.numeric(datetest)
> >
> > to get 11328.
> >
> > But I do not obtain the inverse tranformation :
> >
> > datetest<-as.Date(datetest,"%d/%m/%Y")
> >
> > How do we get this please ?
> >
> > Thanks a lot for your solution.
> > Pierre.
> >
> >
-----------------------------------------------------------------------
This message and its attachments are strictly confidential. ...{{dropped}}
Try structure(11328, class = "Date") or just class(datetest) <- "Date" -roger pierre clauss wrote:> Hi everybody, > I need your precious help for, I think, a simple request, but I do not manage to solve this. > > When I use a "table" function with dates in the rows, the rows are coerced to number after the table function. > > So I need to transform the row names into date format. But I do not manage. > > Therefore, for an example, I manage to write this : > > datetest<-"06/01/2001" > datetest<-as.Date(datetest,"%d/%m/%Y") > datetest<-as.numeric(datetest) > > to get 11328. > > But I do not obtain the inverse tranformation : > > datetest<-as.Date(datetest,"%d/%m/%Y") > > How do we get this please ? > > Thanks a lot for your solution. > Pierre. > > > > [[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 >-- Roger D. Peng | http://www.biostat.jhsph.edu/~rpeng/
If I understand your question correctly, then my suggestion is to try table( format(datetest), other.variable) instead of table(datetest, other.variable) -Don At 4:23 PM +0000 7/11/06, pierre clauss wrote:>Hi everybody, >I need your precious help for, I think, a simple request, but I do >not manage to solve this. > >When I use a "table" function with dates in the rows, the rows are >coerced to number after the table function. > >So I need to transform the row names into date format. But I do not manage. > >Therefore, for an example, I manage to write this : > >datetest<-"06/01/2001" >datetest<-as.Date(datetest,"%d/%m/%Y") >datetest<-as.numeric(datetest) > >to get 11328. > >But I do not obtain the inverse tranformation : > >datetest<-as.Date(datetest,"%d/%m/%Y") > >How do we get this please ? > >Thanks a lot for your solution. >Pierre. > > > > [[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-- --------------------------------- Don MacQueen Lawrence Livermore National Laboratory Livermore, CA, USA