You need to use some data to work, so I'll do something.
# Make fake data x <- c('A','B','C') dat <- expand.grid(x, x) dat$Var3 <- rnorm(9)
We can use the R base for this. I'm not very good at the 'reshape' function, but you can do it. After that, the column names will need to be cleared, although
> reshape(dat, idvar = "Var1", timevar = "Var2", direction = "wide") Var1 Var3.A Var3.B Var3.C 1 A -1.2442937 -0.01132871 -0.5693153 2 B -1.6044295 -1.34907504 1.6778866 3 C 0.5393472 -1.00637345 -0.7694940
Alternatively, you can use the dcast function from the reshape2 package. I think the way out is a little cleaner.
> library(reshape2) > dcast(dat, Var1 ~ Var2, value.var = "Var3") Var1 ABC 1 A -1.2442937 -0.01132871 -0.5693153 2 B -1.6044295 -1.34907504 1.6778866 3 C 0.5393472 -1.00637345 -0.7694940
Dason source share