单词中的月份顺序r?

时间:2019-01-27 19:30:08

标签: r

假设我要有一个向量,该向量包含从2012年3月开始的每个月。我想要该月和下一个33。

我该怎么做?

2 个答案:

答案 0 :(得分:0)

I found this

您可以这样做:

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

df

给我:

 [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

答案 1 :(得分:0)

以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"

reprex package(v0.2.1)于2019-01-27创建