1

是否有类似于month.abbR 中的函数可以显示每个月的第一个字母?例如month.abb返回'Jan','Feb'......我希望寻求的函数返回'J','F',......

4

3 回答 3

8

month.abb 对象不是一个函数,而是一个向量。这是请求的模拟:

short.mo <- substr(month.abb, 1,1)

您可以通过以下方式查看其他内置常量:

?Constants
于 2013-10-29T21:23:00.737 回答
7
R> month.abb
 [1] "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"
R> substr(month.abb, 1, 1)
 [1] "J" "F" "M" "A" "M" "J" "J" "A" "S" "O" "N" "D"
R> 

只需将其包装在一个函数中即可。

于 2013-10-29T21:22:52.303 回答
2

这是另一种按名称索引缩写的方法。

abbreviate(month.name, 1, strict=TRUE)
#  January  February     March     April       May      June      July 
#      "J"       "F"       "M"       "A"       "M"       "J"       "J" 
#   August September   October  November  December 
#      "A"       "S"       "O"       "N"       "D" 
于 2013-10-30T12:27:40.437 回答