I would like to transform a semi-long dataframe to long format. However, after the reshape command, there are several warnigns saying "number of items to replace is not a multiple of replacement length". When I open the new dataframe, the format is basically correct but it says the dataframe is corrupt.
What is going on?
This is the command I use. It explicitly asks me to insert a value for idvar:
df2 = reshape(df,
direction="long",
varying=3:ncol(df),
ids="id",
idvar="newid",
timevar="category")
This is the structure of my original dataframe (actually, there are not only cars and trees, but many more categories):
id trial resp.car rt.car color.car resp.tree rt.tree color.tree
1 1 1 500 "blue" 3 765 "green"
1 1 3 534 "green" 1 455 "yellow"
1 2 2 553 "yellow" 2 794 "red"
1 2 3 577 "black" 3 834 "blue"
2 1 1 598 "green" 1 756 "red"
2 1 3 355 "yellow" 3 457 "black"
2 2 3 876 "blue" 1 767 "yellow"
2 2 2 466 "black" 1 439 "green"
Desired result:
id trial category resp rt color
1 1 "car" 1 500 "blue"
1 1 "car" 3 534 "green"
1 2 "car" 2 553 "yellow"
1 2 "car" 3 577 "black"
1 1 "tree" 3 765 "green"
1 1 "tree" 1 455 "yellow"
1 2 "tree" 2 794 "red"
1 2 "tree" 3 834 "blue"
2 1 "car" 1 598 "green"
...