How to most efficiently restructure character string for quick time in data.table

I have a data table with characters in two columns:

01/01/2014 | 00:30
02/01/2014 | 01:00
03/01/2014 | 01:30 etc

The length of this data set varies, but easily exceeds 300,000 lines when running the script. In the end, I know that this script will have to process a dataset of 30,000,000 plus rows.

I currently have pastethem in the following form:

DT[, DateTime := paste(Date, Time)

That leads to:

01/01/2014 00:30
02/01/2014 01:00
03/01/2014 01:30 etc

Then I use as.POSIXctto convert this value to a POSIX date:

DT[, DateTime:= as.POSIXct(x = DateTime, format = "%d/%m/%Y %H:%M")]

This works fine by correctly converting characters, basically, I suppose, because I gave a format argument so that it matches the structure of the character string that it supplied.

fasttime, , format . , :

DT[, DateTime := fastPOSIXct(x = DateTime)]

fasttime " : , , , , , ". :

2006/07/07 00:30
2007/07/07 01:00
2008/07/07 01:30 etc

, as.POSIXct, โ€‹โ€‹ .

fasttime? ? , , fasttime, fasttime ?

0
1

sub, , , , , as.POSIXct:

DT[, DateTime := fastPOSIXct(sub('(\\d*)/(\\d*)/(\\d*) (.*)', '\\3-\\1-\\2 \\4', DateTime))]

, substr , .

+2

All Articles