Re: [R] convert to chron objects

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu 14 Jul 2005 - 14:46:59 EST

An easy to check what you have is to use month.day.year:

> eh <- data.frame(t = c("06/05/2005 01:15:25", "06/07/2005 01:15:25"))
>
> # substring converts factor to character and extracts substring
> chron(dates = substring(eh$t, 1, 10), times = substring(eh$t, 12))
[1] (06/05/05 01:15:25) (06/07/05 01:15:25)
> month.day.year(.Last.value)

$month
[1] 6 6

$day
[1] 5 7

$year
[1] 2005 2005

On 7/14/05, Sean O'Riordain <sean.oriordain@gmail.com> wrote:
> are those dates in m/d/y or d/m/y ?
> ?chron and watch out for
> format = c(dates = "d/m/y", times = "h:m:s")
>
>
> On 13/07/05, Gabor Grothendieck <ggrothendieck@gmail.com> wrote:
> > [I had some emails problems so I am sending this again. Sorry
> > if you get it twice.]
> >
> > On 7/13/05, Gabor Grothendieck <ggrothendieck@gmail.com> wrote:
> > >
> > >
> > > On 7/13/05, Young Cho <iidn01@yahoo.com> wrote:
> > > > Hi,
> > > >
> > > > I have a column of a dataframe which has time stamps
> > > > like:
> > > >
> > > > > eh$t[1]
> > > > [1] 06/05/2005 01:15:25
> > > >
> > > > and was wondering how to convert it to chron variable.
> > > > Thanks a lot.
> > >
> > >
> > >
> > >
> > >
> > Try this:
> >
> > # test data frame eh containing a factor variable t
> > eh <- data.frame(t = c("06/05/2005 01:15:25", "06/07/2005 01:15:25"))
> >
> > # substring converts factor to character and extracts substring
> > chron(dates = substring(eh$t, 1, 10), times = substring(eh$t, 12))
> >
> > See ?chron for more info. There is an article on dates in
> > R News 4/1 and although it does not specifically answer this
> > question it may be useful with chron and also provides a
> > reference to more chron info elsewhere.
> >
> > ______________________________________________
> > R-help@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
> >
>



R-help@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 Received on Thu Jul 14 14:52:03 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:38 EST