Well, there is no function called "weeks" in chron. Funny that the help mentions it.
You can, however, use normal POSIXct objects and extract the week with: dts <- dates(c("02/27/92", "02/27/92")) dts.posx <- as.POSIXct(dts) result <- as.integer(format(dts.posx,format="%W")) HTH Jannis --- Christopher W Ryan <cr...@binghamton.edu> schrieb am Di, 30.8.2011: > Von: Christopher W Ryan <cr...@binghamton.edu> > Betreff: [R] having trouble extracting week from chron object > An: R-help@r-project.org > Datum: Dienstag, 30. August, 2011 17:36 Uhr > Running R 2.13.1 on Windows XP. > I would like to get week of the year (1-52) for each date. > > library(chron) > dts <- dates(c("02/27/92", "02/27/92", > "01/14/92","02/28/92", "02/01/92")) > dts > dts.chron <- as.chron(dts) > dts.chron > class(dts.chron) > # all of these component extractions work: > months(dts.chron) > weekdays(dts.chron) > years(dts.chron) > quarters(dts.chron) > # but weeks() doesn't seem to work > weeks(dts.chron) > > ?chron tells me: . . . The functions days(), months(), > quarters(), > years(), weeks(), weekdays(), hours(), minutes(), and > seconds() take > any chron object as input and extract the corresponding > time interval > . . . . > > Any advice? > > Thanks. > > Chris Ryan > SUNY Upstate Medical University Clinical Campus at > Binghamton > Binghamton, NY > > ______________________________________________ > R-help@r-project.org > 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. > ______________________________________________ R-help@r-project.org 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.