0

I'm trying to form a data frame (input_data_user) with five columns as shown below.

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)

As data frame needs equal length for creation i've combined the vectors into lists of equal length '3' across the board.

But in-spite of this i'm still getting an error :

> 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

Can you please suggest any alternatives ?

Jaap
  • 81,064
  • 34
  • 182
  • 193
  • It's about the length of the vectors, they still differ. – Heroka Feb 28 '16 at 18:43
  • See the [marked duplicate](http://stackoverflow.com/questions/9547518/creating-a-data-frame-where-a-column-is-a-list)- you can solve your problem by putting `I()` around the list columns: `input_data_user = data.frame(Questions,Question_Name,I(Overall_answers),I(Overall_target_answers))` – David Robinson Feb 28 '16 at 18:43
  • Thank you so much, David. That is super helpful. – Pratyush Tallapragada Feb 28 '16 at 18:45

0 Answers0