[R] character to time problem

John Kane jrkrideau at yahoo.ca
Sat Jun 9 12:50:08 CEST 2007


Thanks. I read your code too quickly.  I'll have a
look at the R News article. I read it last year but
apparently have forgotten just about all of it. :(


--- Gabor Grothendieck <ggrothendieck at gmail.com>
wrote:

> The code in my post uses "Date" class, not POSIX.
> sort.POSIXlt is never invoked.  Suggest you read the
> help desk article in R News 4/1 for more.
> 
> On 6/8/07, John Kane <jrkrideau at yahoo.ca> wrote:
> > Looks much better. I seldom use dates for much and
> > didn't think to look at the sort.POSIXlt function.
> >
> > If I understand this correctly the sort.POSIXlt
> with
> > na.last = FALSE is dropping all the NAs.  Very
> nice.
> >
> >
> > --- Gabor Grothendieck <ggrothendieck at gmail.com>
> > wrote:
> >
> > > Perhaps you want one of these:
> > >
> > > > sort(as.Date(aa$times, "%d/%m/%Y"))
> > > [1] "1995-03-02" "2001-05-12" "2007-02-14"
> > >
> > > > sort(as.Date(aa$times, "%d/%m/%Y"), na.last =
> > > TRUE)
> > > [1] "1995-03-02" "2001-05-12" "2007-02-14" NA
> > >    NA
> > > [6] NA
> > >
> > >
> > > On 6/7/07, John Kane <jrkrideau at yahoo.ca> wrote:
> > > > I am trying to clean up some dates and I am
> > > clearly
> > > > doing something wrong.  I have laid out an
> example
> > > > that seems to show what is happening with the
> > > "real"
> > > > data.  The  coding is lousy but it looks like
> it
> > > > should have worked.
> > > >
> > > > Can anyone suggest a) why I am getting that NA
> > > > appearing after the strptime() command and b)
> why
> > > the
> > > > NA is disappearing in the sort()? It happens
> with
> > > > na.rm=TRUE  and na.rm=FALSE
> > > >
> -------------------------------------------------
> > > > aa  <- data.frame( c("12/05/2001", " ",
> > > "30/02/1995",
> > > > NA, "14/02/2007", "M" ) )
> > > > names(aa)  <- "times"
> > > > aa[is.na(aa)] <- "M"
> > > > aa[aa==" "]  <- "M"
> > > > bb <- unlist(subset(aa, aa[,1] !="M"))
> > > > dates <- strptime(bb, "%d/%m/%Y")
> > > > dates
> > > > sort(dates)
> > > >
> --------------------------------------------------
> > > >
> > > > Session Info
> > > > R version 2.4.1 (2006-12-18)
> > > > i386-pc-mingw32
> > > >
> > > > locale:
> > > > LC_COLLATE=English_Canada.1252;
> > > > LC_CTYPE=English_Canada.1252;
> > > > LC_MONETARY=English_Canada.1252;
> > > > LC_NUMERIC=C;LC_TIME=English_Canada.1252
> > > >
> > > > attached base packages:
> > > > [1] "stats"     "graphics"  "grDevices"
> "utils"
> > > > "datasets"  "methods"   "base"
> > > >
> > > > other attached packages:
> > > >  gdata   Hmisc
> > > > "2.3.1" "3.3-2"
> > > >
> > > >  (Yes I know I'm out of date but I don't like
> > > > upgrading just as I am finishing a project)
> > > >
> > > > Thanks
> > > >
> > > > ______________________________________________
> > > > 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
> > > > and provide commented, minimal,
> self-contained,
> > > reproducible code.
> > > >
> > >
> >
> >
> >
> >      Be smarter than spam. See how smart SpamGuard
> is at giving junk email the boot with the All-new

> http://mrd.mail.yahoo.com/try_beta?.intl=ca
> >
> >
>



More information about the R-help mailing list