How to calculate possible combinations of elements of a vector in GAUSS

Is there a way in GAUSS to calculate all the possible combinations of a list of length N take K at a time?

1 Answer



0



The GAUSS function combinate will return the indices of all possible combinations of a vector of length N taken K at a time. Each row of this function will contain the indices of a different combination. For example:

x = { 0.35, 1.2, 0.9, 4.7 };

//calculate the indices of all combinations
cmb = combinate(4, 2);
print cmb;

will return the indices:

1        2 
1        3 
1        4 
2        3 
2        4 
3        4 

Using these indices you can print out each of the combinations like this:

//loop through and print all combinations
for i(1, rows(cmb), 1);
	print x[cmb[i,.]];
endfor;

which will return the following output:

0.35 
1.20 

0.35 
0.90 

0.35 
4.70 

1.20 
0.90 

1.20 
4.70 

0.90 
4.70 

aptech

1,393

Your Answer


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 30 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy