由于我在写这篇文章之前曾经指出这是重复的,所以无论如何我都会将它添加为答案。基本上包fasttime
可以帮助你IF你有日期后1970-01-01 00:00:00
和他们GMT
和他们的格式year, month, day, hour, minute, second
的。如果你可以重写你的日期格式,然后fastPOSIXct
会很快:
# data
date <- c("2013/5/31 23:30" , "2013/5/31 23:35" , "2013/5/31 23:40" , "2013/5/31 23:45")
require(fasttime)
# fasttime function
dates.ft <- fastPOSIXct(date , tz = "GMT")
# base function
dates <- as.POSIXct(date , format= "%Y/%m/%d %H:%M")
# rough comparison
require(microbenchmark)
microbenchmark(fastPOSIXct(date , tz = "GMT") , as.POSIXct(date , format= "%Y/%m/%d %H:%M") , times = 100L)
#Unit: microseconds
# expr min lq median uq max neval
# fastPOSIXct(date, tz = "GMT") 19.598 21.699 24.148 25.5485 215.927 100
# as.POSIXct(date, format = "%Y/%m/%d %H:%M") 160.633 163.433 168.332 181.9800 278.220 100
但问题是,是能更快日期转换为一种格式fasttime
可以接受或只使用as.POSIXct
或购买更快的计算机?!
http://stackoverflow.com/questions/14218297/convert-string-date-to-r-date-fast-for-all-dates –
有包[快速时间](http://www.rforge。 net/fasttime /),但它需要一个特定的格式。 – Roland
http://stackoverflow.com/questions/12898318/convert-character-to-date-quickly-in-r –