在R中创建具有不均匀向量的数据帧

时间:2016-02-28 18:37:47

标签: r vector dataframe

我正在尝试形成一个包含五列的数据框(input_data_user),如下所示。

Questions = c('A','B','C')
Question_Name = c('AR','AT','IT')
Answers_1 = c('Yes','No','Not sure')
Answers_2 = c('Very high','High','Average','Low','Very low')
Answers_3 = c('Yes','No','Not sure/do not buy in this category')
Overall_answers = list(Answers_1, Answers_2, Answers_3)
Target_answer_1 = c('Yes')
Target_answer_2 = c('Very high','high')
Target_answer_3 = c('Yes')
Overall_target_answers = list(Target_answer_1, Target_answer_2, Target_answer_3)

input_data_user = data.frame(Questions,Question_Name,Overall_answers,Overall_target_answers)

由于数据帧需要相同的创建长度,我已将矢量组合到整个电路板上等长“3”的列表中。

但是尽管如此,我仍然会收到错误:

> input_data_user = data.frame(Questions,Question_Name,Overall_answers,Overall_target_answers)
Error in data.frame(c("Yes", "No", "Not sure"), c("Very high", "High",  : 
  arguments imply differing number of rows: 3, 5

你能否提出任何其他选择?

0 个答案:

没有答案