[R] one question about the loop

jim holtman jholtman at gmail.com
Sun Jul 8 02:08:04 CEST 2007


Is this what you want?

> t(combn(5,2))
      [,1] [,2]
 [1,]    1    2
 [2,]    1    3
 [3,]    1    4
 [4,]    1    5
 [5,]    2    3
 [6,]    2    4
 [7,]    2    5
 [8,]    3    4
 [9,]    3    5
[10,]    4    5
>


On 7/7/07, Zhang Jian <jzhang1982 at gmail.com> wrote:
> Hi.
> I want to get a series data just like this:
> sp1 sp2
> 1   2
> 1   3
> 1   4
> 1   5
> 2   3
> 2   4
> 2   5
> 3   4
> 3   5
> 4   5
>
> I can get one part of the data every time, but I can get the data directly.
> I try to use the loop, but it can not work. How to get it ? Thanks.
>
> pair.fn=function(i,sp=5){res=data.frame(sp1=rep(i,(sp-i)),sp2=(i+1):sp)
> return(res)}
> pair.fn(1)
> pair.fn(2)
> .....
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list