# [R] What is an alternative to expand.grid if create a long vector?

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Mon Apr 19 18:02:02 CEST 2021

Hello,

If you want to process the data by rows, then maybe you should consider
a custom function that divides the problem in small chunks and process
one chunk at a time.

But even so, at 8 bytes per double, 100^10 rows is

(100^10*8)/(1024^4)  # Tera bytes
#[1] 727595761

It will take you a very, very long time to process.

Revise the problem?

Hope this helps,

Às 13:35 de 19/04/21, Shah Alam escreveu:
> Dear All,
>
> I would like to know that is there any problem in *expand.grid* function or
> it is a limitation of this function.
>
> I am trying to create a combination of elements using expand.grid function.
>
> A <- expand.grid(
> c(seq(0.001, 0.1, length.out = 100)),
> c(seq(0.0001, 0.001, length.out = 100)),
> c(seq(0.38, 0.42, length.out = 100)),
> c(seq(0.12, 0.18, length.out = 100)))
>
> Four combinations work fine. However, If I increase the combinations up to
> ten. The following error appears.
>
>   A <- expand.grid(
> c(seq(0.001, 1, length.out = 100)),
> c(seq(0.0001, 0.001, length.out = 100)),
> c(seq(0.38, 0.42, length.out = 100)),
> c(seq(0.12, 0.18, length.out = 100)),
> c(seq(0.01, 0.04, length.out = 100)),
> c(seq(0.0001, 0.001, length.out = 100)),
> c(seq(0.0001, 0.001, length.out = 100)),
> c(seq(0.001, 0.01, length.out = 100)),
> c(seq(0.01, 0.3, length.out = 100))
> )
>
> *Error in rep.int <http://rep.int>(rep.int <http://rep.int>(seq_len(nx),
> rep.int <http://rep.int>(rep.fac, nx)), orep) :   invalid 'times' value*
>
> After reducing the length to 10. It produced a different type of error
>
> A <- expand.grid(
> c(seq(0.001, 0.005, length.out = 10)),
> c(seq(0.0001, 0.0005, length.out = 10)),
> c(seq(0.38, 0.42, length.out = 5)),
> c(seq(0.12, 0.18, length.out = 7)),
> c(seq(0.01, 0.04, length.out = 5)),
> c(seq(0.0001, 0.001, length.out = 10)),
> c(seq(0.0001, 0.001, length.out = 10)),
> c(seq(0.001, 0.01, length.out = 10)),
> c(seq(0.1, 0.8, length.out = 8))
> )
>
> *Error: cannot allocate vector of size 1.0 Gb*
>
> What is an alternative to expand.grid if create a long vector based on 10
> elements?
>
> With kind regards,
> Shah Alam
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help