as.Date returns NA 如果应用于列表
as.Date returns NA if applied to a list
我想让 R 识别这个列表:
[1] "Ago12" "Ago13" "Ago14" "Ago15" "Ago16" "Ago17" "Ago18"
[8] "Apr12" "Apr13" "Apr14" "Apr15" "Apr16" "Apr17" "Apr18"
[15] "Apr19" "Dic12" "Dic13" "Dic14" "Dic15" "Dic16" "Dic17"
[22] "Dic18" "Feb12" "Feb13" "Feb14" "Feb15" "Feb16" "Feb17"
[29] "Feb18" "Feb19" "Gen12" "Gen13" "Gen14" "Gen15" "Gen16"
[36] "Gen17" "Gen18" "Gen19" "Giu12" "Giu13" "Giu14" "Giu15"
[43] "Giu16" "Giu17" "Giu18" "Giu19" "Lug12" "Lug13" "Lug14"
[50] "Lug15" "Lug16" "Lug17" "Lug18" "Lug19" "Mag12" "Mag13"
[57] "Mag14" "Mag15" "Mag16" "Mag17" "Mag18" "Mag19" "Mar12"
[64] "Mar13" "Mar14" "Mar15" "Mar16" "Mar17" "Mar18" "Mar19"
[71] "Nov12" "Nov13" "Nov14" "Nov15" "Nov16" "Nov17" "Nov18"
[78] "Ott12" "Ott13" "Ott14" "Ott15" "Ott16" "Ott17" "Ott18"
[85] "Set12" "Set13" "Set14" "Set15" "Set16" "Set17" "Set18"
作为日期向量使用它来绘制一些系列。当我 运行
time<-as.Date(datecorr,format="%b%y")
我得到了 NA。
我还尝试更改系统语言和时间
Sys.setlocale("LC_TIME","it_IT.UTF-8")
, 但它仍然不起作用。
我想知道我在做什么有什么问题
感谢帮助!
编辑:谢谢大家它运行良好
假设最后的注释中显示的输入可重复设置区域设置,然后将 as.yearmon
和 as.Date
与指定的格式字符串一起使用。您可以考虑省略 as.Date
部分,因为它实际上是您要表示的 year/month。 scale_x_yearmon()
可以与 ggplot2 一起使用。
library(zoo)
Sys.setlocale(locale = "Italian")
as.Date(as.yearmon(x, format = "%b%y"))
给予:
[1] "2012-08-01" "2013-08-01" "2014-08-01" "2015-08-01" "2016-08-01"
[6] "2017-08-01" "2018-08-01" "2012-04-01" "2013-04-01" "2014-04-01"
[11] "2015-04-01" "2016-04-01" "2017-04-01" "2018-04-01" "2019-04-01"
[16] "2012-12-01" "2013-12-01" "2014-12-01" "2015-12-01" "2016-12-01"
[21] "2017-12-01" "2018-12-01" "2012-02-01" "2013-02-01" "2014-02-01"
[26] "2015-02-01" "2016-02-01" "2017-02-01" "2018-02-01" "2019-02-01"
[31] "2012-01-01" "2013-01-01" "2014-01-01" "2015-01-01" "2016-01-01"
[36] "2017-01-01" "2018-01-01" "2019-01-01" "2012-06-01" "2013-06-01"
[41] "2014-06-01" "2015-06-01" "2016-06-01" "2017-06-01" "2018-06-01"
[46] "2019-06-01" "2012-07-01" "2013-07-01" "2014-07-01" "2015-07-01"
[51] "2016-07-01" "2017-07-01" "2018-07-01" "2019-07-01" "2012-05-01"
[56] "2013-05-01" "2014-05-01" "2015-05-01" "2016-05-01" "2017-05-01"
[61] "2018-05-01" "2019-05-01" "2012-03-01" "2013-03-01" "2014-03-01"
[66] "2015-03-01" "2016-03-01" "2017-03-01" "2018-03-01" "2019-03-01"
[71] "2012-11-01" "2013-11-01" "2014-11-01" "2015-11-01" "2016-11-01"
[76] "2017-11-01" "2018-11-01" "2012-10-01" "2013-10-01" "2014-10-01"
[81] "2015-10-01" "2016-10-01" "2017-10-01" "2018-10-01" "2012-09-01"
[86] "2013-09-01" "2014-09-01" "2015-09-01" "2016-09-01" "2017-09-01"
[91] "2018-09-01"
备注
Lines <- '"Ago12" "Ago13" "Ago14" "Ago15" "Ago16" "Ago17" "Ago18"
"Apr12" "Apr13" "Apr14" "Apr15" "Apr16" "Apr17" "Apr18"
"Apr19" "Dic12" "Dic13" "Dic14" "Dic15" "Dic16" "Dic17"
"Dic18" "Feb12" "Feb13" "Feb14" "Feb15" "Feb16" "Feb17"
"Feb18" "Feb19" "Gen12" "Gen13" "Gen14" "Gen15" "Gen16"
"Gen17" "Gen18" "Gen19" "Giu12" "Giu13" "Giu14" "Giu15"
"Giu16" "Giu17" "Giu18" "Giu19" "Lug12" "Lug13" "Lug14"
"Lug15" "Lug16" "Lug17" "Lug18" "Lug19" "Mag12" "Mag13"
"Mag14" "Mag15" "Mag16" "Mag17" "Mag18" "Mag19" "Mar12"
"Mar13" "Mar14" "Mar15" "Mar16" "Mar17" "Mar18" "Mar19"
"Nov12" "Nov13" "Nov14" "Nov15" "Nov16" "Nov17" "Nov18"
"Ott12" "Ott13" "Ott14" "Ott15" "Ott16" "Ott17" "Ott18"
"Set12" "Set13" "Set14" "Set15" "Set16" "Set17" "Set18"'
x <- scan(text = Lines, what = "", quiet = TRUE)
我想让 R 识别这个列表:
[1] "Ago12" "Ago13" "Ago14" "Ago15" "Ago16" "Ago17" "Ago18"
[8] "Apr12" "Apr13" "Apr14" "Apr15" "Apr16" "Apr17" "Apr18"
[15] "Apr19" "Dic12" "Dic13" "Dic14" "Dic15" "Dic16" "Dic17"
[22] "Dic18" "Feb12" "Feb13" "Feb14" "Feb15" "Feb16" "Feb17"
[29] "Feb18" "Feb19" "Gen12" "Gen13" "Gen14" "Gen15" "Gen16"
[36] "Gen17" "Gen18" "Gen19" "Giu12" "Giu13" "Giu14" "Giu15"
[43] "Giu16" "Giu17" "Giu18" "Giu19" "Lug12" "Lug13" "Lug14"
[50] "Lug15" "Lug16" "Lug17" "Lug18" "Lug19" "Mag12" "Mag13"
[57] "Mag14" "Mag15" "Mag16" "Mag17" "Mag18" "Mag19" "Mar12"
[64] "Mar13" "Mar14" "Mar15" "Mar16" "Mar17" "Mar18" "Mar19"
[71] "Nov12" "Nov13" "Nov14" "Nov15" "Nov16" "Nov17" "Nov18"
[78] "Ott12" "Ott13" "Ott14" "Ott15" "Ott16" "Ott17" "Ott18"
[85] "Set12" "Set13" "Set14" "Set15" "Set16" "Set17" "Set18"
作为日期向量使用它来绘制一些系列。当我 运行
time<-as.Date(datecorr,format="%b%y")
我得到了 NA。
我还尝试更改系统语言和时间
Sys.setlocale("LC_TIME","it_IT.UTF-8")
, 但它仍然不起作用。
我想知道我在做什么有什么问题
感谢帮助!
编辑:谢谢大家它运行良好
假设最后的注释中显示的输入可重复设置区域设置,然后将 as.yearmon
和 as.Date
与指定的格式字符串一起使用。您可以考虑省略 as.Date
部分,因为它实际上是您要表示的 year/month。 scale_x_yearmon()
可以与 ggplot2 一起使用。
library(zoo)
Sys.setlocale(locale = "Italian")
as.Date(as.yearmon(x, format = "%b%y"))
给予:
[1] "2012-08-01" "2013-08-01" "2014-08-01" "2015-08-01" "2016-08-01"
[6] "2017-08-01" "2018-08-01" "2012-04-01" "2013-04-01" "2014-04-01"
[11] "2015-04-01" "2016-04-01" "2017-04-01" "2018-04-01" "2019-04-01"
[16] "2012-12-01" "2013-12-01" "2014-12-01" "2015-12-01" "2016-12-01"
[21] "2017-12-01" "2018-12-01" "2012-02-01" "2013-02-01" "2014-02-01"
[26] "2015-02-01" "2016-02-01" "2017-02-01" "2018-02-01" "2019-02-01"
[31] "2012-01-01" "2013-01-01" "2014-01-01" "2015-01-01" "2016-01-01"
[36] "2017-01-01" "2018-01-01" "2019-01-01" "2012-06-01" "2013-06-01"
[41] "2014-06-01" "2015-06-01" "2016-06-01" "2017-06-01" "2018-06-01"
[46] "2019-06-01" "2012-07-01" "2013-07-01" "2014-07-01" "2015-07-01"
[51] "2016-07-01" "2017-07-01" "2018-07-01" "2019-07-01" "2012-05-01"
[56] "2013-05-01" "2014-05-01" "2015-05-01" "2016-05-01" "2017-05-01"
[61] "2018-05-01" "2019-05-01" "2012-03-01" "2013-03-01" "2014-03-01"
[66] "2015-03-01" "2016-03-01" "2017-03-01" "2018-03-01" "2019-03-01"
[71] "2012-11-01" "2013-11-01" "2014-11-01" "2015-11-01" "2016-11-01"
[76] "2017-11-01" "2018-11-01" "2012-10-01" "2013-10-01" "2014-10-01"
[81] "2015-10-01" "2016-10-01" "2017-10-01" "2018-10-01" "2012-09-01"
[86] "2013-09-01" "2014-09-01" "2015-09-01" "2016-09-01" "2017-09-01"
[91] "2018-09-01"
备注
Lines <- '"Ago12" "Ago13" "Ago14" "Ago15" "Ago16" "Ago17" "Ago18"
"Apr12" "Apr13" "Apr14" "Apr15" "Apr16" "Apr17" "Apr18"
"Apr19" "Dic12" "Dic13" "Dic14" "Dic15" "Dic16" "Dic17"
"Dic18" "Feb12" "Feb13" "Feb14" "Feb15" "Feb16" "Feb17"
"Feb18" "Feb19" "Gen12" "Gen13" "Gen14" "Gen15" "Gen16"
"Gen17" "Gen18" "Gen19" "Giu12" "Giu13" "Giu14" "Giu15"
"Giu16" "Giu17" "Giu18" "Giu19" "Lug12" "Lug13" "Lug14"
"Lug15" "Lug16" "Lug17" "Lug18" "Lug19" "Mag12" "Mag13"
"Mag14" "Mag15" "Mag16" "Mag17" "Mag18" "Mag19" "Mar12"
"Mar13" "Mar14" "Mar15" "Mar16" "Mar17" "Mar18" "Mar19"
"Nov12" "Nov13" "Nov14" "Nov15" "Nov16" "Nov17" "Nov18"
"Ott12" "Ott13" "Ott14" "Ott15" "Ott16" "Ott17" "Ott18"
"Set12" "Set13" "Set14" "Set15" "Set16" "Set17" "Set18"'
x <- scan(text = Lines, what = "", quiet = TRUE)