regex - How to most efficiently convert a character string of "01 Jan 2014" to POSIXct i.e. "2014-01-01" yyyy-mm-dd -
i have partial answer problem here, understand far explained: how efficiently restructure character string fasttime in data.table
however, task has been extended, , needs deal variation of orginal formatting.
i have large dataset, column of dates of character class in form of:
01 jan 2014
or:
dd mmm yyyy
which want restructure feed fastposixct
accepts character input in posixct
order:
yyyy-mm-dd
the above linked question notes efficient approach use regex , supply output fast.time
. here need extend include method understand monthly abbreviations, convert numeric, rearrange? how this? know there month.abb
built in constant. should using this, or there smarter way?
what using lubridate
:
x <- "01 jan 2014" x [1] "01 jan 2014" library(lubridate) dmy(x) [1] "2014-01-01 utc"
of course lubridate
functions accept tz
argument too. see complete list of acceptable arguments see olsonnames()
benchmark
i decided update answer empirical data using micro benchmark
package , lubridate
option use fasstime.
library(micro benchmark) microbenchmark(dmy(x), times = 10000) unit: milliseconds expr min lq mean median uq max neval dmy(x) 1.992639 2.02567 2.142212 2.041514 2.07153 39.1384 10000 options(lubridate.fasttime = t) microbenchmark(dmy(x), times = 10000) unit: milliseconds expr min lq mean median uq max neval dmy(x) 1.993326 2.02488 2.136748 2.039467 2.065326 163.2008 10000
Comments
Post a Comment