我有一个time series
数据框df
date lang revenue year month
1 01/01/2014 DE-DE 8146.5 2014 1
2 02/01/2014 EN-GB 31416.95 2014 1
3 03/01/2014 EN-US 152646 2014 1
4 04/01/2014 ES-ES 15523 2014 1
5 05/01/2014 FR-FR 4221.5 2014 1
6 06/01/2014 IT-IT 12971.7 2014 1
...
我的目标是:创建一个取决于**week variable**
日历的date
并将其保存到我的df
。
我将date
格式更改为factor
到date
df$date = as.Date(df$date)
然而,结果变得像这样
"0001-01-20" "0002-01-20" "0003-01-20" "0004-01-20" ...
我尝试添加time format
df$date = as.Date(df$date, format = "%d-%m-%y")
但结果仍然相同。
有什么问题?
strftime(df$date,format="%W")
然而,结果没有任何意义:
"03" "03" "03" "03" "03" "03" "03" "03" "02" "02" "02" "02" "02" "02" "02" "02" "02" "03" "03"
[20] "03" "03" "03" "03" "03" "03" "03" "03" "03" "03" "03" "03" "03" "03" "03" "03" "03" "03" "03"
[39] "03"
我想知道哪里出错了? (当第一个问题解决后,第二个问题可能会解决?)
谢谢!
答案 0 :(得分:2)
我们需要指定format
as.Date(df$date, "%d/%m/%Y")