I have a data set as shown below:
Frame | X.axis | Y.axis | Z.axis
-------|--------|--------|--------
1 | 0.2 | 0.215 | 0.965
-------|--------|--------|--------
2 | 0.54 | 1.25 | 2.219
-------|--------|--------|--------
1 | 2.124 | 2.418 | 1.35
-------|--------|--------|--------
2 | -1.2 | 0.49 | 1.87
-------|--------|--------|--------
1 | 6.42 | -1.28 | 7.1
-------|--------|--------|--------
2 | 6.45 | -2.5 | 8.5
I want to reshape the above table into something like as shown here:
frame1.X.axis | frame1.Y.axis | frame1.Z.axis | frame2.X.axis | frame2.Y.axis | frame2.Z.axis
--------|--------|--------|--------|--------|--------
0.2 | 0.215 | 0.965 | 0.54 | 1.25 | 2.219
--------|--------|--------|--------|--------|--------
2.124 | 2.418 | 1.35 | -1.2 | 0.49 | 1.87
--------|--------|--------|--------|--------|--------
6.42 | -1.28 | 7.1 | 6.45 | -2.5 | 8.5
How can the above task be achieved ?
Important Note:
The real data set has 16 frames instead of 2. And the columns to be spread are 90 instead of 3. So I don't want a function which requires me to mention the new column names manually. I want the column names to be automatically named by the function somehow.
I have tried using tidyr
package's spread
function but I couldn't do it using that. I then tried the reshape
function but it also asks for the new column names.