特定年份的一周中的天数

时间:2017-04-10 09:25:14

标签: r

我有两列,Yearweekoftheyear(0-52)。我如何知道一年中的特定周,例如2014年的第一周或最后一周有多少天?

1 个答案:

答案 0 :(得分:0)

根据周开始日调整如下:

strptime(paste(my_year,my_week,"Saturday"), "%Y %U %A")-strptime(paste(my_year,my_week,"Sunday"), "%Y %U %A")+1

strptime(paste("2014","1","Saturday"), "%Y %U %A")-strptime(paste("2014","1","Sunday"), "%Y %U %A")+1
Time difference of 7 days

与以下相同

strptime(paste("2014","2","Sunday"), "%Y %U %A")-strptime(paste("2014","1","Sunday"), "%Y %U %A")
Time difference of 7 days