Effectively create an extended xx memory location

Probably a very simple question, but I would like to be able to set the variables a and b in order to be able to create data.frame or data.table from expand.grid in R.

eg. if a=5 , b=3

what I want so that I can get the same result as

 expand.grid(seq(0,1,by=1/5),seq(0,1,by=1/5), seq(0,1,by=1/5)) 

and if a=3 and b=4 I get

 expand.grid(seq(0,1,by=1/3), seq(0,1,by=1/3), seq(0,1,by=1/3), seq(0,1,by=1/3)) 

i.e. b is the number of columns .... and a is the size of the interval.

thanks

EDIT

Ideally, I would put numbers for a about 100 and b about 30, is there something that is fast and efficient with memory when creating this ... maybe something like data.table ?

+4
source share
3 answers

Something like this should work using replicate and do.call

 exgrid <- function(a, b){ do.call(expand.grid,replicate(b , seq(0,1,by = 1/a), simplify = FALSE)) } 
+4
source

This will generate data.frame (ffdf) with 100 Mio lines without memory problems. It uses the ff package. You can enlarge the columns as you wish. Note that this can generate quite some data if you play with columns.

 require(ffbase) x <- expand.ffgrid(ff(1:1000), ff(1:1000), ff(1:100)) dim(x) x[1:5, ] 
+3
source

I believe this brings you closer to what you need:

 b <- 4 expand.grid(rep(list(seq(0,1,by=1/3)), b)) 
+2
source

Source: https://habr.com/ru/post/1447658/


All Articles