I am using R to try to transform my data frame from "long-ish" to "wide-ish" and I have searched in vain for an answer that uses data similar in structure to mine. Here are my data:
| ID | NAME | V1 | V2 | V3 |
|------|------|-------|----:|-----:|
| 1001 | Bob | Red | 302 | 0.50 |
| 1001 | Bob | Blue | 737 | 0.50 |
| 1002 | Jim | Red | 432 | 0.14 |
| 1002 | Jim | Blue | 643 | 0.60 |
| 1002 | Jim | Green | 34 | 0.46 |
| 1006 | Dan | Red | 876 | 1.25 |
And this is how I would like the final data (wide) to look:
| ID | NAME | V2.Red | V2.Blue | V2.Green | V3.Red | V3.Blue | V3.Green |
|------|------|-------:|--------:|---------:|-------:|--------:|---------:|
| 1001 | Bob | 302 | 737 | N/A | 0.50 | 0.50 | N/A |
| 1002 | Jim | 432 | 643 | 34 | 0.14 | 0.60 | 0.46 |
| 1006 | Dan | 876 | N/A | N/A | 1.25 | N/A | N/A |
So, basically, I'm collapsing all of the same ID rows into one row (with accompanying NAME) so that the total number of rows is equal to the number of unique ID values.
I am then using the unique values of V1 to create as many columns as there are unique values in V1 times the number of "extra variables"--V2, V3. (I have many more variables of the V2 and V3 type.
Thanks in advance!