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
.
(我将按运输方式生成出行时间和成本的所有组合,但不知道如何在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
表示每对模式的组合编号。)
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.
(我使用了expand.grid()
但是它只返回模式,时间和成本(3 * 2 * 3)的18种组合,而没有考虑一对传输模式的置换。)
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. (我更喜欢在带有分组变量(例如comb
的data.frame
进行制作。)
Permute groups in a data.frame R
(在data.frame R中置换组)
How to calculate permutations of group labels with R?
(如何使用R计算组标签的排列?)
It would be highly appreciated to generate all combinations simply..
(非常希望简单地生成所有组合。)
ask by Hideo.S translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…