我的问题是:如何根据Sys.Date()生成每年的12月?
例如,根据今天的日期,产生2022年12月。
> Sys.Date()
[1] "2022-08-27"
就要生成"202212"。
到了2023年,则需要自动生成
"202312"
谢谢!
楼主: wx2123
|
822
4
[问答] R产生年月的问题 |
硕士生 67%
-
|
回帖推荐## 只提取年月,函数1❯ gsub('-', '', substring(Sys.Date(), 1, 7))
[1] "202209"✔
❯ class(gsub('-', '', substring(Sys.Date(), 1, 7)))
[1] "character"✔
## 只提取年月,函数2❯ format(Sys.Date(), '%Y%m')
[1] "202209"
✔
❯ class(format(Sys.Date(), '%Y%m'))
[1] "character"
✔
❯ microbenchmark::microbenchmark(gsub = gsub('-', '', ...
| ||
京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明 免责及隐私声明