我正在xls
使用gdata
. 我正在转换日期列,as.Date
用于转换日期
根据手册as.Date
,日期来源取决于平台,因此我正在确定相应地使用哪个来源
.origin <- ifelse(Sys.info()[['sysname']] == "Windows", "1899-12-30", "1904-01-01")
as.Date(myData$Date, origin=.origin)
但是,我想知道是否应该考虑读取文件的平台或写入文件的平台?
对于它的价值,我目前正在一个没有 excel 的 linux 机器上测试代码,并且正确的日期是通过使用origin="1904-01-01"
引用'?as.Date'
## date given as number of days since 1900-01-01 (a date in 1989)
as.Date(32768, origin = "1900-01-01")
## 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
## 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)