[R] construct a list that consists of lists
Henrique Dallazuanna
wwwhsd at gmail.com
Fri Mar 12 18:56:16 CET 2010
You can do this also, using replicate:
replicate(6, list(para1 = 1:5, para2 = 5:9), simplify = FALSE)
On Fri, Mar 12, 2010 at 2:51 PM, Zhongyi Yuan <zhongyi-yuan at uiowa.edu> wrote:
> Hi Jim,
>
> Dennis Murphy solved my problem by the following code.
> Thank you for you suggestion. Will check out listBuilder function too.
>
> best,
> Zhongyi
>
> # (2) A little more general: prespecify the number of list components
> # and run a one-line loop to populate the list
>> l <- vector('list', 6)
>> for(i in seq_along(l)) l[[i]] <- v
>> l
> [[1]]
> [[1]]$para1
> [1] 1 2 3 4 5
>
> [[1]]$para2
> [1] 5 6 7 8 9
>
>
> [[2]]
> [[2]]$para1
> [1] 1 2 3 4 5
>
> [[2]]$para2
> [1] 5 6 7 8 9
>
>
> [[3]]
> [[3]]$para1
> [1] 1 2 3 4 5
>
> [[3]]$para2
> [1] 5 6 7 8 9
>
>
> [[4]]
> [[4]]$para1
> [1] 1 2 3 4 5
>
> [[4]]$para2
> [1] 5 6 7 8 9
>
>
> [[5]]
> [[5]]$para1
> [1] 1 2 3 4 5
>
> [[5]]$para2
> [1] 5 6 7 8 9
>
>
> [[6]]
> [[6]]$para1
> [1] 1 2 3 4 5
>
> [[6]]$para2
> [1] 5 6 7 8 9
>
>
> On Fri, Mar 12, 2010 at 3:06 AM, Jim Lemon <jim at bitwrit.com.au> wrote:
>
>> On 03/12/2010 05:13 PM, Zhongyi Yuan wrote:
>>
>>> Dear R users:
>>>
>>> I am hoping that someone can help with constructing a list that consists
>>> of
>>> list with the number of lists variable.
>>> i.e. to find a convenient express(or loop sentences) to realize the
>>> following:
>>> list( list(para1=p1, para2=p2), list(para1=p1, para2=p2), ....,
>>> list(para1=p1,para2=p2) )
>>>
>>> Hi Zhongyi,
>> Have a look at the listBuilder function in the crank package.
>>
>> Jim
>>
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
More information about the R-help
mailing list