[R] Vectors of years, months, and days to dates?
p.dalgaard at biostat.ku.dk
Mon Jun 7 18:35:26 CEST 2004
Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:
> On Mon, 7 Jun 2004, Shin, Daehyok wrote:
> > The interface for dates in R is a little confusing to me.
> > I want to create a vector of Date objects from vectors of years, months, and
> > days.
> > One solution I found is:
> > years <- c(1991, 1992)
> > months <- c(1, 10)
> > days <- c(1, 2)
> > dates <- as.Date(ISOdate(years, months, days))
> > But, in this solution the ISOdate function converts the vectors into
> > characters,
> > which can cause serious performance and memory loss
> > when the vectors of years, months, and days are huge.
> Really? You have measured the loss? A million causes no problem for
> example, and what are you going to do with a million dates that is
> instantaneous and worthwhile? And a million dates are hardly going to be
> unique so you only need to convert the unique values.
However, considering what goes on in ISOdatetime, one might as well do
as.Date(paste(years, months, days, sep="-"))
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help