2014-09-30 89 views
2

我在格式化为字符串像Lubridate获得本周某一天的日期()

我用lubridate一个数据帧列的日期,以确定我的日期属于周:

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

给我一周40

我按那个星期分组并汇总我的数据。现在我想把那一周变回日期。 那么我怎样才能得到那一周某一天的日期呢?

Monday例如Week 402014将是日期09/29/3014。所以我想设置每个Week 40到那个日期。

回答

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. 
+0

我怎样才能得到的结果在 “2014年9月30日” 格式? – brno792 2014-09-30 20:24:16

+1

格式(as.Date(“2-39-2014”,'%u-%W-%Y'),'%m /%d /%Y') – agstudy 2014-09-30 20:25:07

相关问题