Why is as.Date slow on a character vector?

后端 未结 5 1050
囚心锁ツ
囚心锁ツ 2020-11-27 16:36

I started using data.table package in R to boost performance of my code. I am using the following code:

sp500 <- read.csv(\'../rawdata/GMTSP.csv\')
days &         


        
5条回答
  •  渐次进展
    2020-11-27 17:12

    This is an old question, but I think this tiny trick it might be useful. If you have multiple rows with the same date, you can do

    data[, date := as.Date(date[1]), by = date]

    It's much faster since it only processes each date once (in my dataset of 40 million rows it goes from 25 seconds to 0.5 seconds).

提交回复
热议问题