I have a quite big dataframe with the following structure:
image coef v3 v4 v5 v6 ... v20
1 A 0 1 2 3
1 B 2 4 6 5
1 C 1 2 4 7
1 D 4 5 6 4
2 A 2 3 4 5
2 B 2 3 4 5
2 C 2 3 4 5
2 D 2 3 4 5
And I need to end up with "flattened" structure on the coef variable for each image index. Now each image have the variables with the shape [4:20] but i need it to be [1:80] with the patern [A,B,C,D,A',B',C',D'...]. like this:
image v3 v4 v5 v6 v7 v8 v9 v10 ... v80
1 0 2 1 4 1 4 2 5
2 2 2 2 2 3 3 3 3
I tried to do:
reshape(df, timevar = "coef", idvar = "image", direction = "wide")
But i gives me the Error :
Error in data[, timevar] : subindex out of bounds
Also I tried the library Reshape2 with:
dcast(df, image~coef, value.var= )
but since I have more than one value.var column I cannot figure out how to do it.