创建日期向量,更改为因子和格式

时间:2019-03-21 14:09:54

标签: r

我有以下代码:

gsub("-","/",paste(cut(seq(as.POSIXct(Sys.Date(),format="%d-%b-%y"), by = "-1 day", length.out = 10),"days"),collapse = ","))

输出:

"2019/03/20,2019/03/19,2019/03/18,2019/03/17,2019/03/16,2019/03/15,2019/03/14,2019/03/13,2019/03/12,2019/03/11"

但是所需的结果是

'20/03/2019','19/03/2019','18/03/2019','17/03/2019','16/03/2019','15/03/2019','14/03/2019','13/03/2019','12/03/2019','11/03/2019'

我该怎么做?

致谢

1 个答案:

答案 0 :(得分:4)

不确定要执行的操作,但是可以通过执行

生成所需的输出
format(Sys.Date() - 1:10, "%d/%m/%Y")

#[1] "20/03/2019" "19/03/2019" "18/03/2019" "17/03/2019" "16/03/2019" "15/03/2019" 
#    "14/03/2019" "13/03/2019" "12/03/2019" "11/03/2019"