[R] Alternative to extended recode sintax?

David Winsemius dwinsemius at comcast.net
Sat Dec 18 14:39:58 CET 2010


On Dec 17, 2010, at 11:08 AM, Luca Meyer wrote:

x= factor(c("2009-03-30 00:00:00", "2009-04-06 00:00:00", "2009-04-13  
00:00:00", "2009-04-20 00:00:00", "2009-04-27 00:00:00", "2009-05-04  
00:00:00" ,"2009-05-11 00:00:00", "2009-05-18 00:00:00"))
require(lubridate)
xd=as.POSIXct(x)
week(xd)
# [1] 13 14 15 16 17 18 19 20
  year(xd)
# [1] 2009 2009 2009 2009 2009 2009 2009 2009
  paste(year(xd), " W",week(xd), sep="")
#[1] "2009 W13" "2009 W14" "2009 W15" "2009 W16" "2009 W17" "2009 W18"  
"2009 W19" "2009 W20"



David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list