Skip to content
Prev 191714 / 398498 Next

Transform data for repeated measures

On Thu, Aug 27, 2009 at 6:37 PM, Richardson,
Patrick<Patrick.Richardson at vai.org> wrote:
To give a concrete example of what using the reshape package would
look like: (thanks to David for making your example easily
reproducible)

 resp.df <- read.table(textConnection("patient basefev1 fev11h fev12h
fev13h fev14h fev15h fev16h fev17h fev18h drug

 201     2.46   2.68   2.76   2.50   2.30   2.14   2.40   2.33   2.20    a
 202     3.50   3.95   3.65   2.93   2.53   3.04   3.37   3.14   2.62    a
 203     1.96   2.28   2.34   2.29   2.43   2.06   2.18   2.28   2.29    a
 204     3.44   4.08   3.87   3.79   3.30   3.80   3.24   2.98   2.91
  a"), header=TRUE)
closeAllConnections()

library(reshape)
# Identify the variables controlled by your experimental design:
stk.resp <- melt(resp.df, id = c("patient", "drug"))
stk.resp$time <- as.numeric(gsub("[^0-9]", "", stk.resp$variable))

Hadley