r - data.table fast table search -


i have dataset can filtered in multiple dimensions, , wondering if there fast way filtering...

to give bit of background have 6 dimensions of differing sizes, represent data have made mock grid in r last dimension being made bit smaller fits ram.

d1 <- 3 d2 <- 6 d3 <- 24 d4 <- 7 d5 <- 12 d6 <- 10000 # actual dataset 500000  full.dt <- data.table(expand.grid(h1=seq(d1),                                   h2=seq(d2),                                   h3=seq(d3),                                   h4=seq(d4),                                   h5=seq(d5),                                   h6=seq(d6),stringsasfactors=false)) # each permutation , combination produces specific score... # mimicking using runif function full.dt[,score:=runif(nrow(full.dt))] 

i filter 2000 unique values of h6, , single value of h2. doing using lines below....but feel bit slow , wont scale when using true value of d6 of 500000.

it taking 32 seconds on osx 10.10.3, 2.8 ghz intel core i7 , 16 gb 1600 mhz ddr3. using keys help? there ways of speeding up? , there methods of dealing object size vs size of ram issue, (perhaps splitting data separate tables read in separately)? c++ potential answer?

 no.unique.h6.vals <- 2000  h2.val <- 1  chosen.h6.vals <- sample.int(d6,no.unique.h6.vals)   system.time(ff <- full.dt[(h6 %in% chosen.h6.vals) & (h2==h2.val),])     user  system elapsed    15.600   9.571  31.661  

also although 1 type of filter... on data ideally have flexibility filter on of given dimensions, e.g. specific value h3, h4 , h5 etc (e.g.)...

x <- 10000 h1 <- sample.int(d1,x,replace=true) h2 <- sample.int(d2,x,replace=true) h3 <- sample.int(d3,x,replace=true) h4 <- sample.int(d4,x,replace=true) h5 <- sample.int(d5,x,replace=true) h6 <- sample.int(d6,x,replace=true)  g.full <- data.table(h1,h2,h3,h4,h5,h6) 

and filtering on g.full rows...

edit

as per david arenberg's comments

running following line...

setkey(full.dt, h1,h2,h3,h4,h5,h6) 

seems in terms of speed....

system.time(ff3 <- full.dt[data.table(expand.grid(h1=seq(d1),h2=h2.val,h3=seq(d3),h4=seq(d4),h5=seq(d5),h6=chosen.h6.vals,stringsasfactors = false)),])    user  system elapsed   2.762   0.420   3.182 

and helps other situations too:

 system.time(ff4 <- full.dt[g.full])    user  system elapsed    0.024   0.031   0.055  

this seems fast...are there potential solutions ram problem?


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -