I am new to data.tables, so I apologize if this is a very simple question.
I heard that data.tables significantly improves computational times when working with large amounts of data and therefore would like to see if data.table can help speed up the rollapply function.
if we have some one-dimensional data
xts.obj <- xts(rnorm(1e6), order.by=as.POSIXct(Sys.time()-1e6:1), tz="GMT") colnames(xts.obj) <- "rtns"
a simple rolling quantile with a width of 100 and p 0.75 takes an amazingly long time ...
i.e. line of code
xts.obj$quant.75 <- rollapply(xts.obj$rtns,width=100, FUN='quantile', p=0.75)
it seems forever ...
is there anything data.table can do to speed things up? those. Is there a general roll function that can be applied?
maybe a program to convert an xts object to a data.table object to execute a function in an accelerated manner, and then return to xts again at the end?
early
hlm
ps It seems that I did not receive a response to the data.table mailing list, so I am posting here to see if it works out better.
pps with a quick jump with another example using data frames, the data.table solution seems to take longer than the rollapply function, i.e. shown below:
> x <- data.frame(x=rnorm(10000)) > x.dt <- data.table(x) > system.time(l1 <- as.numeric(rollapply(x,width=10,FUN=quantile,p=0.75))) user system elapsed 2.69 0.00 2.68 > system.time(l <- as.numeric(unlist(x.dt[,lapply(1:((nrow(x.dt))-10+1), function(i){ x.dt[i:(i+10-1),quantile(x,p=0.75)]})]))) user system elapsed 11.22 0.00 11.51 > identical(l,l1) [1] TRUE
r xts dataframe data.table apply
hlm Aug 27 '12 at 22:27 2012-08-27 22:27
source share