在R程序中转换exceldate代码(文本样式)

问题很简单:我在R中导入了一个txt数据。但是,我忘了将date格式更改为dd / mm / yyyy。 例如:而不是有30/09/2015我有42277。

当然,我可以回到我的Excel,并从数字更改列格式,并获得dd / mm / yyyy格式很容易。 但是我想在R里面有这样的一个方法。我在这里有几个包,比如XLConnect,但是没有任何东西。

以下是如何转换Excel风格的date:

as.Date(42277, origin="1899-12-30")

as.Date的帮助文件讨论了来自其他时间系统的转换的变幻莫测,并且包括Excel的讨论和示例。

  ## Excel is said to use 1900-01-01 as day 1 (Windows default) or ## 1904-01-01 as day 0 (Mac default), but this is complicated by Excel ## incorrectly treating 1900 as a leap year. ## So for dates (post-1901) from Windows Excel as.Date(35981, origin = "1899-12-30") # 1998-07-05 ## and Mac Excel as.Date(34519, origin = "1904-01-01") # 1998-07-05 ## (these values come from http://support.microsoft.com/kb/214330)