Pardon my new-ness to the R world, thank you kindly in advance for your help.
I would like to analyze the data from an experiment.
The data comes in in Long format, and it needs to be reshaped into wide, but I cannot figure out exactly how to do it. Most of the examples for melt/cast and reshape deal with much simpler dataframes.
Each time the subject answers a question on the experiment, his userid, location, age, and gender are recorded in a single row, then his experimental data on a series of questions are inputed next to those variables. Here's the thing, they may answer any number of questions on the experiment, and they may answer different items (it is quite complicated, but it must be this way).
The raw data looks something like this:
User_id, location, age, gender, Item, Resp
1, CA, 22, M, A, 1
1, CA, 22, M, B, -1
1, CA, 22, M, C, -1
1, CA, 22, M, D, 1
1, CA, 22, M, E,-1
2, MD, 27, F, A, -1
2, MD, 27, F, B, 1
2, MD, 27, F, C, 1
2, MD, 27, F, E, 1
2, MD, 27, F, G, -1
2, MD, 27, F, H, -1
I would like to reshape this data to have each user be on a single row, to look like this:
User_id, location, age, gender, A, B, C, D, E, F, G, H
1, CA, 22, M, 1, -1, -1, 1, -1, 0, 0, 0,
2, MD, 27, F, -1, 1, 1, 1, 0, 1, -1, -1
I think this is just a matter of finding the right reshape equation, but I've been at it for a couple of hours and I can't quite get what I want it too look like, since most of the examples do not have the repeated demographic data, and thus can just be rotated more simply. Very sorry if I have overlooked something simple.