0
我在這裏犯了一個微不足道的錯誤,但無法弄清楚問題是什麼。R strptime星期一從weeknumber怪異的日期
我需要得到一個隨機日期的周的星期一的日期..看來我得到的東西完全不同
mydate <- date("2013-11-05")
format(mydate, "%A") # this is Tuesday, right
#[1] "Tuesday"
month(mydate) # Month November, right
#[1] 11
myyr <- year(mydate); myyr # year is 2013, right
#[1] 2013
day(mydate) # day number is 5, right
#[1] 5
mywk <- isoweek(mydate);mywk # weeknumber is 45, right (yes, not US convention here)
#[1] 45
format(mydate, "%V") # weeknumber is 45, right as well
#[1] "45"
# Monday of week 45 is 2013-11-04 but strptime following gives something else...
strptime(paste0(myyr, "Monday", mywk), "%Y%A%V")
#[1] "2013-11-19 EET"
# and for checking
strptime("2013Monday45","%Y%A%V")
#[1] "2013-11-19 EET"
在此先感謝
不清楚你想要給定日期的日期,但這可能會有所幫助:'d < - as.Date(「2013-11-05」); d - as.numeric(格式(d,「%w」))+ 1' –
根據'?strpitime'看到'%V'是'Accepted,but input on input'。改用'%W'。 – nicola