无法正确使用动物园的 as.yearmon,转换后的列的年份显示为 0086 而不是 1986
您好,感谢您来到这里。
我正在尝试使用 as.yearmon 转换日期,但得到的结果很奇怪,我不知道如何解决这个问题;我尝试在此处和官方软件包指南上进行搜索,但没有找到遇到相同问题的人。 问题是我用 as.yearmon 转换了格式为“月/年”的数据集的列,但结果不正确。
例如,原始DF的列的前3个值为:“1/86”、“2/86”、“3/86”。
使用此函数转换它们后:
library(zoo)
Dates <- Returns
Dates$Month<- zoo::as.yearmon(Dates$Month, "%m / %Y")
[其中“Returns”是原始数据帧,并用修改后的日期标记新数据帧。]
我得到的结果,而不是:“gen 1986”,“feb 1986”,“mar 1986 ”是“gen 0086”、“feb 0086”、“mar 0086”,我不知道为什么。
[我不应该认为“gen”、“feb”、“mar”是意大利语;我不知道这是否重要,我不知道如何将其更改为“一月”,“二月”,“三月”,我想我也必须这样做]
提前感谢您的帮助,如果有的话不清楚请告诉我;我还是个菜鸟。
Hello and thanks for being here.
I'm trying to convert dates with as.yearmon but the results I'm getting are odd and I do not know how to fix this; I tried searching on here and on the offical package guide without finding someone with the same problem.
The problem is that I transformed a column of a dataset which was formatted as "month/year" with as.yearmon but the results were not correct.
For example, the first 3 values of the column of the original DF are: "1/86", "2/86", "3/86".
After using this function to convert them:
library(zoo)
Dates <- Returns
Dates$Month<- zoo::as.yearmon(Dates$Month, "%m / %Y")
[Where "Returns" is the original dataframe and Dates the new one with the modified dates.]
The result I got, instead of being: "gen 1986", "feb 1986", "mar 1986" was "gen 0086", "feb 0086", "mar 0086" and I don know why.
[I should not that "gen", "feb", "mar" are in Italian; I do not know if that matters and I do not know how to change that to "Jan", "Feb", "Mar" which I think I'll have to do as well]
Thanks in advance for your help, if something is not clear just let me know; I'm still a rookie.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用“%m/%y”而不是“%m/%Y”。您的日期没有全年符号。
日期函数返回本地语言环境中的名称。如果您想要英语版本:
每次重新启动 R 时,都会将其设置回您的语言环境。
更多信息此处
You need to use "%m/%y" instead of "%m/%Y". Your dates don't have a the full year notation.
Date functions return the names in the local locale. If you want them in English:
Everytime you restart R, this will be set back to your locale.
More info here on SO