Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any faster alternative to POSIXct in R? [duplicate]

Tags:

r

posixct

I am reading a CSV with fread (as it is quicker than read_csv method), timestamp column is taken as character type.

I want to convert it to POSIXct with: as.POSIXct(strptime(rawTime, "%Y-%m-%d %H:%M:%OS"))

But this POSIXct call is very slow.

enter image description here

Is there any quicker alternatetive to this?

like image 251
Devharsh Trivedi Avatar asked Dec 23 '22 17:12

Devharsh Trivedi


1 Answers

We can use fastPOSIXct from fasttime

library(fasttime)
str1 <- rep("2015-01-01", 1e6)
system.time(fastPOSIXct(str1))
#   user  system elapsed 
#   0.08    0.00    0.08 

system.time(as.POSIXct(str1))
#   user  system elapsed 
#  24.80    0.26   25.33 
like image 191
akrun Avatar answered Jan 31 '23 06:01

akrun