I have the following data frame on R:
| Year | Result | Var1 | Var2 | Var3 |
|---|---|---|---|---|
| 2000 | Positive | 0.5 | 0.2 | 0.3 |
| 2000 | Negative | 0.4 | 0.2 | 0.5 |
| 2001 | Positive | 0.3 | 0.5 | 0.5 |
| 2001 | Negative | 0.3 | 0.2 | 0.3 |
| 2002 | Positive | 0.3 | 0.5 | 0.1 |
| 2002 | Negative | 0.3 | 0.2 | 0.4 |
I am seeking to create the following table:
| Year | Var1.Positive | Var1.Negative | Var2.Positive | Var2.Negative | Var3.Positive | Var2.Positive |
|---|---|---|---|---|---|---|
| 2000 | 0.5 | 0.4 | 0.2 | 0.2 | 0.3 | 0.5 |
| 2001 | 0.3 | 0.3 | 0.5 | 0.2 | 0.5 | 0.3 |
| 2002 | 0.3 | 0.3 | 0.5 | 0.2 | 0.1 | 0.4 |
To do so, I am using reshape:
dat$Result <- as.factor(dat$Result)
df = reshape(dat, idvar = "Result", timevar = "Year", direction = "wide")
But a table of NaNs is delivered. What am I missing?
Thanks !