How can I group days into weeks?

前端 未结 3 2245
猫巷女王i
猫巷女王i 2020-12-17 18:39

In R, how can I associate between a vector of dates (days) and weeks?

Edit: \"weeks\" should be the week index within the date range and not within the year. My apol

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-17 19:36

    Do you just want the number of completed 7 day intervals since the first record?

    dvec <- as.Date("2001-04-01")+0:90
    dweek <- as.numeric(dvec-dvec[1]) %/% 7
    dweek[1:21]
    # [1] 0 0 0 0 0 0 0 1 1 1 1 1 1 1 2 2 2 2 2 2 2
    

提交回复
热议问题