创建每列中包含数字的数据框

时间:2016-04-13 08:15:18

标签: r

我有10000个随机数的模拟

floor(runif(10000, 10,200))

但我需要将数据放在以下列中:

question_id choice1 choice2 choice3 choice4 correct_answer
(1-10000)    1       2       3       4         3

如何使用R question_id获得此值的范围为1到10000,并且在各列中选择重复在1到4之间。在correct_answer列中1到4个选项之间的随机正确答案。

1 个答案:

答案 0 :(得分:1)

这就是你需要的吗?

df  <- data.frame( question_id = seq(1:10000),choice1=1,choice2=2,choice3=3,choice4=4,correct_answer=sample(1:4,10000,T))

head(df)

  question_id choice1 choice2 choice3 choice4 correct_answer
1           1       1       2       3       4              1
2           2       1       2       3       4              3
3           3       1       2       3       4              2
4           4       1       2       3       4              1
5           5       1       2       3       4              1
6           6       1       2       3       4              2
相关问题