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

Shah Alam dr@@|@m@o|@ng| @end|ng |rom gm@||@com
Mon Apr 19 14:35:45 CEST 2021

```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]]

```