[R] Save a list of list and search for values

jim holtman jholtman at gmail.com
Thu Feb 26 15:39:31 CET 2015


You store it as a list of lists and can then use the lapply function
to navigate for values.

result <- lapply(1:10000, function(x){
    mix(param[x])  # whatever your call to 'mix' is with some data
})





Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Thu, Feb 26, 2015 at 9:27 AM, Alaios via R-help <r-help at r-project.org> wrote:
> Dear all,in my code I am using the mix() function that returns results in a list. The result looks like
> List of 10
>  $ parameters  :'data.frame':   2 obs. of  3 variables:
>   ..$ pi   : num [1:2] 0.77 0.23
>   ..$ mu   : num [1:2] -7034 162783
>   ..$ sigma: num [1:2] 20235 95261
>  $ se          :'data.frame':   2 obs. of  3 variables:
>   ..$ pi.se   : num [1:2] 0.0423 0.0423
>   ..$ mu.se   : num [1:2] 177 12422
>   ..$ sigma.se: num [1:2] 1067 65551
>  $ distribution: chr "norm"
>  $ constraint  :List of 8
>   ..$ conpi   : chr "NONE"
>   ..$ conmu   : chr "NONE"
>   ..$ consigma: chr "NONE"
>   ..$ fixpi   : NULL
>   ..$ fixmu   : NULL
>   ..$ fixsigma: NULL
>   ..$ cov     : NULL
>   ..$ size    : NULL
>  $ chisq       : num 28
>  $ df          : num 5
>  $ P           : num 3.67e-05
>  $ vmat        : num [1:5, 1:5] 1.79e-03 -3.69e-01 -1.17e+02 2.95e+01 -2.63e+03 ...
>  $ mixdata     :Classes ‘mixdata’ and 'data.frame':     11 obs. of  2 variables:
>   ..$ X    : num [1:11] 1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 1e+05 ...
>   ..$ count: int [1:11] 993 137 82 30 21 5 7 14 21 2 ...
>  $ usecondit   : logi FALSE
>  - attr(*, "class")= chr "mix"
>
> In my code I am trying around 10.000 fit (and each of these fits returns the list above) and I want to keep those in a way that later on I would be able to search inside all the lists.For example I would like to find inside those 10.000 lists which one has the smallest $chisq value. What would be a suitable way to implement that in R? Luckily I am working in a computer with a lot of ram so storing 10.000 lists temporary in memory before saving to disk would not be a problem.
> What would you suggest me?
> RegardsAlex
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list