[Rd] How to create arbitrary number of loops
sarah.goslee at gmail.com
Thu Mar 29 15:35:27 CEST 2012
That sounds like a job for recursion.
And also, a question for r-help and not r-devel.
On Wed, Mar 28, 2012 at 5:34 PM, Dai, Hongying, <hdai at cmh.edu> wrote:
> Dear R users,
> I'm wondering how I can generate an arbitrary number of loops in R.
> For instance, I can generate two "for" loops to get ICC among any two-way combination among 10 variables. Here is the code
> for (i in 1:(n-1))
> for (j in (i+1):n)
> If I need three-way combination, then a code with three "for" loops will be:
> for (i in 1:(n-2))
> for (j in (i+1):(n-1))
> for (k in (j+1):n)
> But how can I write a code if I need all m=2, 3, 4,... loops for arbitrary m-way combinations?
More information about the R-devel