combn() gives ordered combinations, while expand.grid() gives all combinations.

I'd give worked code but this hints at homework to me.

Sarah

On Wed, Aug 1, 2012 at 10:23 AM, Eik Vettorazzi <e.vettora...@uke.de> wrote:
> Hi,
> not sure if that is what you are looking for, but have a look at
>
> cmb<-t(combn(c(0,3,5,8),2))   #get all pairs of combinations
> cbind(cmb,apply(cmb,1,diff))  #for each pair, get the difference
>
> cheers
>
>
> Am 01.08.2012 12:29, schrieb loyolite270:
>> Hi
>>
>> I need to optimize the below function:
>>
>> a=function(x){
>>      A=x[1]
>>      B=x[2]
>>      C=B-A
>> return(C)
>> }
>>
>> I need to optimize the above function such that x can be any combination of
>> these number (0,3,5,8) of vector length 2
>> (i.e) x can be (3,0), (5,0), (8,0), (3,5), (3,8), (5,8), ...... etc
>>
>> can someone please help me solve this problem ?
>>
>>
>>


-- 
Sarah Goslee
http://www.functionaldiversity.org

______________________________________________
R-help@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.

Reply via email to