as.POSIXlt is nothing to do with chron. You are confusing two systems.
months() is part of base R: days() is not, and it does not say it works
with R's dates.
The answer is on the help page for months(), BTW:
> c(testdate$mday, testdate$year)
[1] 17 98
or look at ?strftime for e.g.
> format(testdate, "%Y")
[1] "1998"> format(testdate, "%d")
[1] "17"
if you want a character string.
On Sun, 3 Feb 2002, John Field wrote:
> Hello r-help,
>
> I'm trying to split a character vector of dates of the form
"dd-mmm-yy"
> into component days, months and years. But
>
> > library(chron)
> >
testdate<-as.POSIXlt(strptime("17-Sep-98","%d-%b-%y"))
> > testdate
> [1] "1998-09-17"
> > months(testdate)
> [1] "September" # which is fine, but for days and years I get
> > days(testdate)
> NULL
> > years(testdate)
> NULL
> >
>
> According to "?days" these should work. What am I doing wrong?
Is there
> an easier way to achieve what I want?
> (I'm running R1.3.0 under Win98).
An R upgrade is long overdue ....
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._