reshapeWide(data, varFixed, varLong, varTime, varDrop)
[data.frame]
: a data frame in 'long' format (repeated
measurements in the same column)[charater]
or [vector(character)]
: names
of classical (non-longitudinal) variables, variables that does not vary with time (like sex, blood groups).[charater]
or [vector(character)]
: names
of longitudinal variables, variables that vary with time (like sex, blood groups).[charater]
:
variable that record the time at witch the longitudinal variable have
been measured (like ages, year, month).[charater]
or [vector(character)]
:
variable that should not appears in the new data frame.varFixed
, varLong
, varTime
and
varDrop
is missing, it will take the value of all the variable
non already include in one of the fields.reshape
.summary(Indometh)
reshapeWide(Indometh,varTime="time",varFixed="Subject",varLong="conc")
df2 <- data.frame(id = rep(1:4, rep(2,4)),
visit = I(rep(c("Before","After"), 4)),
x = rnorm(4), y = runif(4),
sex=rep(c("H","F","H"),time=c(4,2,2)))[1:7,]
reshapeWide(df2,varTime="visit",varFixed="id",varLong=c("x","y"))
reshapeWide(df2,varTime="visit",varFixed=c("id","sex"),varLong=c("x"))
reshapeWide(df2,varTime="visit",varFixed=c("id","sex"),varDrop="")
Run the code above in your browser using DataLab