Re: [R] R loop help

2010-04-06 Thread casperyc
Hi there, That's exactly what I want. I have checked ?combn out, but I could get the following, suppose that I want ALL possible combinations of them, as this == apply( combn(paste('x', 1:4, sep =""), 2), 2, function(v) get(v[1])*get(v[2])

Re: [R] R loop help

2010-03-27 Thread Patrick Burns
An aside to the main question: I don't think that i+1:3 is doing what you think it is. On 26/03/2010 23:01, casperyc wrote: Hi, I am tring to write a loop to compute this, == x1=c( rep(-1,4), rep(1,4) ) x2=c( rep(c(-1,-1,1,1),2)

Re: [R] R loop help

2010-03-26 Thread Jorge Ivan Velez
Hi casperyc, Here is a suggestion: # all at once apply(combn(paste('x', 1:3, sep =""), 2), 2, function(v) get(v[1])*get(v[2]) ) # step by step thex <- paste('x', 1:3, sep ="") thex combs <- combn(thex, 2) combs apply(combs, 2, function(v) get(v[1])*get(v[2]) ) x1, x2 and x3 correspo

[R] R loop help

2010-03-26 Thread casperyc
Hi, I am tring to write a loop to compute this, == x1=c( rep(-1,4), rep(1,4) ) x2=c( rep(c(-1,-1,1,1),2) ) x3=c( rep(c(-1,1),4) ) x1*x2 x1*x3 x2*x3 suppose i have x1,x2,x3