I am an R (and coding novice) and I am looking for a way to reconfigure Table A show below into Table B.
Table A:
type x1 x2 x3
A 4 6
A bit late to the party, but this can also be done quite easily with the dcast function of the data.table package because you can use multiple value.var's in it:
library(data.table)
dcast(setDT(d), type ~ rowid(type), value.var = c('x1','x2','x3'), sep = '')
which gives:
type x11 x12 x13 x21 x22 x23 x31 x32 x33 1: A 4 7 9 6 4 6 9 1 2 2: B 1 2 NA 3 7 NA 8 9 NA
You can also do this in base R with:
d$num <- ave(d$x1, d$type, FUN = seq_along)
reshape(d, idvar = 'type', direction = 'wide', timevar = 'num', sep = '')