I have a long format dataframe dogs that I\'m trying to reformat to wide using the reshape() function. It currently looks like so:
dogid month year traini
In this case, using base reshape
, you essentially want an interaction()
of the three time variables to define your wide variables, so:
idvars <- c("dogid","home","school")
grpvars <- c("year","month","trainingtype")
outvar <- "timeincomp"
time <- interaction(dat[grpvars])
reshape(
cbind(dat[c(idvars,outvar)],time),
idvar=idvars,
timevar="time",
direction="wide"
)
# dogid home school timeincomp.2014.1.1 timeincomp.2014.2.1 timeincomp.2015.12.2
#1 12345 1 1 340 360 NA
#3 31323 7 3 500 520 440