0

I am preparing a questionnaire to ask which transport mode do the respondents use in different conditions in terms of its travel time and cost.

There are three transport modes, two levels of travel time and three levels of travel cost as below:

mode <- c(1:3)
time <- c(1:2)
cost <- c(1:3)

I would generate all combinations of travel time and cost by transport mode but do not know how to generate it easily in R.

In the questionnaire, it shows three modes in one pair of modes with different conditions like the example below. comb indicates combination number of each pair of modes.

comb  mode time cost
1     1    1    1
1     2    1    1
1     3    1    1

2     1    1    1
2     2    2    1
2     3    2    1

3     1    2    1
3     2    1    2
3     3    1    1

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

5     1    1    2
5     2    2    1
5     3    1    3

6     1    1    1
6     2    1    1
6     3    1    1

7     1    1    1
7     2    1    1
7     3    1    1

8     1    1    1
8     2    1    1
8     3    1    1
..... continues till fulfilling all combinations

I used expand.grid() but it returns just 18 combinations of mode, time and cost (3*2*3) without taking permutation by a pair of transport mode into account. I also tried several permutation functions but it may not bring my desired result. I prefer to make it in a data.frame with grouping variable such as comb in the example.

Permute groups in a data.frame R

How to calculate permutations of group labels with R?

It would be highly appreciated to generate all combinations simply..

HSJ
  • 687
  • 6
  • 16
  • Are ```comb1, comb6, comb7, and comb8``` supposed to be the same? – Cole Dec 01 '19 at 11:44
  • `comb` indicates ID of question. For instance, one questionnaire contains three questions, `comb1`, `comb2`, `comb3` and a respondent select one transport mode from each combination under different conditions of time and cost. – HSJ Dec 01 '19 at 11:55
  • And you can confirm that the combinations I mentioned are supposed to be identical? If so, it may help to expand the logic on what you are doing and include how many ```comb``` you are expecting. – Cole Dec 01 '19 at 12:04

0 Answers0