I create proportional tables based on the xts object. Since this is part of a large program that (unfortunately) requires about 10 ^ 6 cycles, it creates a rather bottleneck, and I would like to speed it up.
This is an example of where I started:
library(quantmod) test.xts <- xts(sample(seq(1,5, by=.5), 50, replace=T), as.Date(1:50)) system.time(for(i in 1:10000){ prop.table(table(test.xts)) }) >user system elapsed 19.86 0.00 18.58
I already changed the xts to the matrix and led to a significant increase in speed. I just mention that this is xts initially in case I skip something with xts, which will speed it up beyond what I already saw, turning it into a matrix.
test.mat <- as.matrix(test.xts) system.time(for(i in 1:10000){ prop.table(table(test.mat)) }) >user system elapsed 2.78 0.00 2.90
But I would really like it to be as fast as possible, so I hope that others have suggestions for further improvements there. I hope there will be an obvious approach.
Another piece of information is that the output from these tables ultimately merges with a similar output from another time period, so the dimensions should remain named. (Ie, I need to be able to match the proportion for the value β10β at time 1 with the fraction β10β at time 2).
Any help is greatly appreciated.
source share