我有一个日期向量,格式为BW01.68,BW02.68,...,BW26.10。BW代表“双周”,因此,例如,“ BW01.68”代表1968年的第一个双周,“ BW26.10”代表2010年的第26个(也是最后一个)双周。使用R,如何将这个向量转换为实际的日期,例如格式为01-01-1968、01-15-1968,...,2010年12月16日?R是否有办法确切知道每个双周对应的日期?谢谢你的帮助!
替代解决方案。
biwks <- c("BW01.68", "BW02.68", "BW26.10")
bw <- substr(biwks,3,4)
yr <- substr(biwks,6,7)
yr <- paste0(ifelse(as.numeric(yr) > 15,"19","20"),yr)
# the %j in the date format is the number of days into the year
as.Date(paste(((as.numeric(bw)-1) * 14) + 1,yr,sep="-"),format="%j-%Y")
#[1] "1968-01-01" "1968-01-15" "2010-12-17"
尽管我会注意到“双周”似乎是一个奇怪的衡量标准,但我不能确定仅使用14天的时间段是您工作的目的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句