Hi!
It's been years since the last time I've had to do this. I thought it was simple, but I haven't been able to figure this one out...
.... how do I switch from long to wide format in R?
Like, say I have this:
How do I turn this so that there are 10 columns (g.1, g.2, g.3,...g.10) and 10 rows? I remember this was super easy to do with reshape... alas:
For some reason, every time I try something I can't seem to get it! I'm not married to reshape. I know the tidyverse can also do this. I'm just not as well-versed on it but at this point I'll try anything!
It's been years since the last time I've had to do this. I thought it was simple, but I haven't been able to figure this one out...
.... how do I switch from long to wide format in R?
Like, say I have this:
Code:
x <- rnorm(100)
g <- rep(1:10, each=10)
df <- data.frame(x,g)
Code:
> reshape(data=df, timevar="g", direction="wide")
Error in `[.data.frame`(data, , idvar) : undefined columns selected