[R] from expand.grid to a list (lapply)
Gerrit Eichner
Gerrit.Eichner at math.uni-giessen.de
Wed Feb 25 11:13:16 CET 2015
Hie Alaiso,
try to simply apply lapply() to your data frame. It should work w/o any
further operation since data frames are lists (check with is.list()).
Hth -- Gerrit
On Wed, 25 Feb 2015, Alaios via R-help wrote:
> Hi all,I would like to use an expand.grid functionality that would give
> me at the end a listso far my code looks like:
> sigma_max_On_seq<-seq(0.05,100,length.out=10000)
> mean_max_On_seq<-seq(2,10000),length.out=10000)
> expandMeanSigmaOn<-expand.grid(mean_max_On_seq,mean_max_On_seq,sigma_max_On_seq,sigma_max_On_seq)
> that gives me at the end all the possible combinations as a data
> frame.
> Browse[1]> str((expandMeanSigmaOn))
> 'data.frame': XXX obs. of 4 variables:
> $ Var1: num 1 11432 22864 34295 45727 ...
> $ Var2: num 1 1 1 1 1 1 1 1 1 1 ...
> $ Var3: num 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 ...
> $ Var4: num 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 ...
> - attr(*, "out.attrs")=List of 2
> ..$ dim : int 10 10 10 10
> ..$ dimnames:List of 4
> .. ..$ Var1: chr "Var1= 1.00" "Var1= 11432.44" "Var1= 22863.89" "Var1= 34295.33" ...
> .. ..$ Var2: chr "Var2= 1.00" "Var2= 11432.44" "Var2= 22863.89" "Var2= 34295.33" ...
> .. ..$ Var3: chr "Var3= 0.05000" "Var3= 31.48065" "Var3= 62.91131" "Var3= 94.34196" ...
> .. ..$ Var4: chr "Var4= 0.05000" "Var4= 31.48065" "Var4= 62.91131" "Var4= 94.34196" ...
>
> but I want to have a list that I would be able to use it as input into
> a lapply function. The lapply should use then each list entry
> independently giving as input variables only the current
> $Var1,$Var2,$Var3,$Var4
>
> How I can convert in R the data.frame into a list?
> I would like to thank you in advance for your replyRegardsAlex
More information about the R-help
mailing list