简体   繁体   English

单词中的月份顺序r?

[英]Sequence of Months in Words r?

Let's say I want to have a vector that contains each month in order starting with March 2012. I want that month and the next 33. 假设我想要一个向量,该向量包含从2012年3月开始的每个月。我想要该月和下一个33。

How would I do this? 我该怎么做?

I found this 我找到了这个

You can do this: 你可以这样做:

df <- ymd("2012-03-01")+ months(0:33)

df

Give me: 给我吗:

 [1] "2012-03-01" "2012-04-01" "2012-05-01" "2012-06-01" "2012-07-01" "2012-08-01" "2012-09-01"
 [8] "2012-10-01" "2012-11-01" "2012-12-01" "2013-01-01" "2013-02-01" "2013-03-01" "2013-04-01"
[15] "2013-05-01" "2013-06-01" "2013-07-01" "2013-08-01" "2013-09-01" "2013-10-01" "2013-11-01"
[22] "2013-12-01" "2014-01-01" "2014-02-01" "2014-03-01" "2014-04-01" "2014-05-01" "2014-06-01"
[29] "2014-07-01" "2014-08-01" "2014-09-01" "2014-10-01" "2014-11-01" "2014-12-01

With base R: 使用基数R:

dates <- seq.Date(from = as.Date("2012-03-01"), length.out = 33, by = "month")
format(dates, "%B %Y")
#>  [1] "March 2012"     "April 2012"     "May 2012"       "June 2012"     
#>  [5] "July 2012"      "August 2012"    "September 2012" "October 2012"  
#>  [9] "November 2012"  "December 2012"  "January 2013"   "February 2013" 
#> [13] "March 2013"     "April 2013"     "May 2013"       "June 2013"     
#> [17] "July 2013"      "August 2013"    "September 2013" "October 2013"  
#> [21] "November 2013"  "December 2013"  "January 2014"   "February 2014" 
#> [25] "March 2014"     "April 2014"     "May 2014"       "June 2014"     
#> [29] "July 2014"      "August 2014"    "September 2014" "October 2014"  
#> [33] "November 2014"

Created on 2019-01-27 by the reprex package (v0.2.1) reprex软件包 (v0.2.1)创建于2019-01-27

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM