Skip to content
Prev 387849 / 398502 Next

What is an alternative to expand.grid if create a long vector?

Hi



Keep your mails on the list. Actually you did not say much about your data and 
the way how do you want to model them. There are plenty of modelling functions 
in R starting with e.g. lm but I am not aware of a procedure in which you just 
design your explanatory variables to set plausible model. But I am not expert 
in statistics and this list is not ment for solving statistical problems.



Cheers

Petr





From: Shah Alam <dr.alamsolangi at gmail.com>
Sent: Monday, April 19, 2021 5:20 PM
To: PIKAL Petr <petr.pikal at precheza.cz>
Subject: Re: [R] What is an alternative to expand.grid if create a long 
vector?



Dear Petr,



Thanks for your response. I am designing a model with 10 unknown parameters. 
generating the combination of unknown parameters will be used in the model to 
estimate the set of vectors that fits well to actual data. Is there any other 
was to do it? I also used randomLHS function from lhs package. But, it did not 
serve the purpose.



Best regards,

Shah Alam





On Mon, 19 Apr 2021 at 16:07, PIKAL Petr <petr.pikal at precheza.cz
<mailto:petr.pikal at precheza.cz> > wrote:
Hi

Actually expand.grid produces data frame and not vector. And dimension of
the data frame is "big"
[1] 100000000         4
'data.frame':   100000000 obs. of  4 variables:
 $ Var1: num  0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01 ...
 $ Var2: num  1e-04 1e-04 1e-04 1e-04 1e-04 1e-04 1e-04 1e-04 1e-04 1e-04
...
 $ Var3: num  0.38 0.38 0.38 0.38 0.38 0.38 0.38 0.38 0.38 0.38 ...
 $ Var4: num  0.12 0.12 0.12 0.12 0.12 0.12 0.12 0.12 0.12 0.12 ...
 - attr(*, "out.attrs")=List of 2
  ..$ dim     : int [1:4] 100 100 100 100
  ..$ dimnames:List of 4
  .. ..$ Var1: chr [1:100] "Var1=0.001" "Var1=0.002" "Var1=0.003"
"Var1=0.004" ...
  .. ..$ Var2: chr [1:100] "Var2=0.0001000000" "Var2=0.0001090909"
"Var2=0.0001181818" "Var2=0.0001272727" ...
  .. ..$ Var3: chr [1:100] "Var3=0.3800000" "Var3=0.3804040"
"Var3=0.3808081" "Var3=0.3812121" ...
  .. ..$ Var4: chr [1:100] "Var4=0.1200000" "Var4=0.1206061"
"Var4=0.1212121" "Var4=0.1218182" ...
in case of 4 sequences 1e8 rows, 4 columns
in case of 10 sequences 1e20 rows and 10 columns
in your last example 1.4e8 rows and 10 columns which probably cross the
memory capacity of your PC.

Maybe you could increase memory of you PC. If I am correct to store the
first you need about 3.2GB, to strore the last 11.2 GB.

May I ask what you want to do with such a big object?

Cheers
Petr
vector?
or it
function.
100)),
100)),
100)),
= 100))
5)),
10)),