Lubridate获取一周中某一天的日期()

时间:2014-09-30 19:43:01

标签: r lubridate

我在数据框列中的日期格式为字符串,如09/30/2014

我使用lubridate来确定我的日期所属的周数:

library(lubridate)
week(mdy("09/30/2014")

给我一​​周40

我按周分组并汇总我的数据。现在我想把那一周变回一个约会。 那么如何才能获得该周特定日期的日期?

Monday例如Week 40中的2014将是09/29/3014的日期。所以我想将每个Week 40设置为该日期。

1 个答案:

答案 0 :(得分:7)

您可以执行以下操作:

## 2 for Tuesday ,39 week number, 2014 the year
as.Date("2-39-2014",'%u-%W-%Y')
"2014-09-30"

你在哪里:

> %u :Weekday as a decimal number (1–7, Monday is 1).
> %W :Week of the year as decimal number (00–53) using Monday as the first day of week
> %Y :Year with century.
相关问题