0

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 !

rawr
  • 19,873
  • 4
  • 42
  • 74
panino00
  • 13
  • 4
  • 2
    I don't get any `NaN`s for the data shared. Can you provide `dput(dat)` to reproduce the issue. Nonetheless, you should use `df – Ronak Shah Aug 20 '21 at 04:48

0 Answers0