我正在尝试使用zoo在data.table中使用两列来表示Date。
数据$ Date< - as.yearmon(粘贴(数据$月,数据$年),"%Y%m") 但我在NA的所有内容
以下是数据的样子:
Year Month State County Rate
2015 October California Santa Clara County 4.0
2015 March California Santa Clara County 4.4
2015 August California Santa Clara County 4.1
2015 May California Santa Clara County 4.1
2015 January California Santa Clara County 4.7
答案 0 :(得分:3)
你有两个问题。一,您正在粘贴Month
,Year
,但告诉您发送Year
,Month
。此外,%m
表示月份为小数1-12。您希望%B
获取月份的全名。您需要切换粘贴的顺序并更改格式。
data$Date <- as.yearmon(paste(data$Year,data$Month), "%Y %B")
Year Month State County Rate Date
1: 2015 October California Santa Clara County 4.0 Oct 2015
2: 2015 March California Santa Clara County 4.4 Mar 2015
3: 2015 August California Santa Clara County 4.1 Aug 2015
4: 2015 May California Santa Clara County 4.1 May 2015
5: 2015 January California Santa Clara County 4.7 Jan 2015