Skip to content

chron problem: extracting days and years

2 messages · John Field, Brian Ripley

#
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).

Many thanks,
John Field

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
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:
[1] 17  98

or look at ?strftime for e.g.
[1] "1998"
[1] "17"

if you want a character string.
On Sun, 3 Feb 2002, John Field wrote:

            
An R upgrade is long overdue ....