[R] Vectors of years, months, and days to dates?

Shin, Daehyok sdhyok at email.unc.edu
Mon Jun 7 18:32:23 CEST 2004


Thanks, but, what I want is to convert three vectors of years, months, and
days directly into POSIXlt or Date objects
without creating character vectors.

Daehyok Shin (Peter)
Terrestrial Hydrological Ecosystem Modellers
Geography Department
University of North Carolina-Chapel Hill
sdhyok at email.unc.edu

"We can do no great things,
only small things with great love."
                         - Mother Teresa

> -----Original Message-----
> From: james.holtman at convergys.com [mailto:james.holtman at convergys.com]
> Sent: Monday, June 07, 2004 PM 12:15
> To: sdhyok at email.unc.edu
> Subject: Re: [R] Vectors of years, months, and days to dates?
>
>
>
>
>
>
> If you 'unclass' dates you will get a numeric vector that just
> has the days
> since the epoch.  Is this what you want?
>
> > years <- c(1991, 1992)
> > months <- c(1, 10)
> > days <- c(1, 2)
> >
> > dates <- as.Date(ISOdate(years, months, days))
> > dates
> [1] "1991-01-01" "1992-10-02"
> > str(dates)
> Class 'Date'  num [1:2] 7670 8310
> > unclass(dates)
> [1] 7670 8310
> >
> __________________________________________________________
> James Holtman        "What is the problem you are trying to solve?"
> Executive Technical Consultant  --  Office of Technology, Convergys
> james.holtman at convergys.com
> +1 (513) 723-2929
>
>
>
>
>                       "Shin, Daehyok"
>
>                       <sdhyok at email.unc.edu        To:       "R,
> Help" <r-help at stat.math.ethz.ch>
>                       >                            cc:
>
>                       Sent by:                     Subject:  [R]
> Vectors of years, months, and days to dates?
>                       r-help-bounces at stat.m
>
>                       ath.ethz.ch
>
>
>
>
>
>                       06/07/2004 11:16
>
>                       Please respond to
>
>                       sdhyok
>
>
>
>
>
>
>
>
>
> 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.
> I am quite sure there is much better solution for it. What is it?
>
> Thanks.
>
> Daehyok Shin
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.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