I have the following data frame
id datestamp hrofday val1 val2 val3
a 20120401 0 3.2 0 1
a 20120401 1 3.3 4 0
a 20120401 2 3.4 6 0
...
a 20120401 23 7.3 0 2
It represents a user-id followed by hour of day, val1 val2 & val3.
I want to use cast to put the data frame in the following shape using either reshape or base R. For every id I want the values in val1 in each of the 24 fields and simultaneously find the total for val2 & val3. e.g. shown below
id datestamp val1.0 val1.1 val1.2 ... val1.23 total.val2 total.val3
a 20120401 3.2 3.3 3.4 ... 7.3 10 3
...
Any help much appreciated. Thanks in advance.
Not precisely what you wanted (slightly different column names):