Hi, Given a frame with calendar date's: "2005-07-01", "2005-07-02","2005-07-03","2005-07-04","2005-07-05",etc. I want to extract the following from these dates: week number month number year number Any ideas how to accomplish this? Many thanks. Regards, Richard
d = as.POSIXlt(c("2005-07-01", "2005-07-02", "2005-07-03", "2005-07-04", "2005-07-05")) d$mon and d$year will get you part way there. That is assuming your dates are formated yyyy-mm-dd. strptime() might also be useful. Richard van Wingerden wrote:> Hi, > > Given a frame with calendar date's: > > "2005-07-01", "2005-07-02","2005-07-03","2005-07-04","2005-07-05",etc. > > I want to extract the following from these dates: > > week number > month number > year number > > Any ideas how to accomplish this? > > Many thanks. > > Regards, > Richard > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! R-project.org/posting-guide.html >
D = as.POSIXlt(c("2005-07-01", "2005-07-02", "2005-07-03", "2005-07-04", "2005-07-05"))> (Years = 1900+D$year)[1] 2005 2005 2005 2005 2005> (Months = D$mon+1)[1] 7 7 7 7 7> weekdays(D)[1] "Friday" "Saturday" "Sunday" "Monday" "Tuesday" # you better check this one carefully !!! (Weeknumbers = floor((D$yday+7)/7)) JeeBee On Mon, 12 Dec 2005 12:59:11 +0100, Richard van Wingerden wrote:> Hi, > > Given a frame with calendar date's: > > "2005-07-01", "2005-07-02","2005-07-03","2005-07-04","2005-07-05",etc. > > I want to extract the following from these dates: > > week number > month number > year number > > Any ideas how to accomplish this? > > Many thanks. > > Regards, > Richard > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! R-project.org/posting-guide.html