以已知顺序生成输入

时间:2015-06-22 10:17:30

标签: r dataframe rep

我有兴趣为此question中提到的示例生成输入。我使用以下代码段生成了输入

data.frame(grade = rep(LETTERS[1:5],4,rep=TRUE), 
       sex = c( rep(c('male','female'), each=5), rep('male',4),rep('female', each=6)),
       class=rep(c(1,2),each=10))

它给出了以下输出:

   grade    sex class
1      A   male     1
2      B   male     1
3      C   male     1
4      D   male     1
5      E   male     1
6      A female     1
7      B female     1
8      C female     1
9      D female     1
10     E female     1
11     A   male     2
12     B   male     2
13     C   male     2
14     D   male     2
15     E female     2
16     A female     2
17     B female     2
18     C female     2
19     D female     2
20     E female     2

我不确定这是否是生成此输出的最佳方法。想知道是否有任何聪明的做法。

如果这不是一个问题,请提出正确的提问方式。

0 个答案:

没有答案