 # 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?

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,728

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,728

### Have a Specific Question?

Get a real answer from a real person

### Need Support?

Get help from our friendly experts.