[R] Using split() several times in a row?

Martin Maechler maechler at stat.math.ethz.ch
Sat Mar 31 21:22:05 CEST 2007


>>>>> "SteT" == Stephen Tucker <brown_emu at yahoo.com>
>>>>>     on Fri, 30 Mar 2007 18:41:39 -0700 (PDT) writes:

  [..]

    SteT> For dates, I usually store them as "POSIXct" classes
    SteT> in data frames, but according to Gabor Grothendieck
    SteT> and Thomas Petzoldt's R Help Desk article
    SteT> <http://cran.r-project.org/doc/Rnews/Rnews_2004-1.pdf>,
    SteT> I should probably be using "chron" date and times...

I don't think you should (and I doubt Gabor and Thomas would
recommend this in every case):

POSIXct (and 'POSIXlt', 'POSIXt' & 'Date') are part of standard R,
and whereas they may seem not as convenient in all cases as "chron"
etc, I'd rather recommed to stick to them in such a case.

    SteT> Nonetheless, POSIXct casses are what I know so I can
    SteT> show you that to get the month out of your column
    SteT> (replace "8.29.97" with your variable), you can do the
    SteT> following:

    SteT> month = format(strptime("8.29.97",format="%m.%d.%y"),format="%m")

    SteT> Or,
    SteT> month = as.data.frame(strsplit("8.29.97","\\."))[1,]

  [......etc..very....useful..advice............]



More information about the R-help mailing list