Re: [R] Transposing by a group variable

2008-02-14 Thread John Kane
How do we know what value corresponds to what new variable? library(reshape) mm <- melt(d, id="group") cast(mm, group~value) will give you something but not quite what you want. --- Shubha Vishwanath Karanth <[EMAIL PROTECTED]> wrote: > Hi R, > > > > Can I transpose a data frame by a part

Re: [R] Transposing by a group variable

2008-02-14 Thread Henrique Dallazuanna
Try also: reshape(cbind(d, time=unlist(sapply(table(d$group), seq))), idvar="group", direction="wide") On 14/02/2008, Shubha Vishwanath Karanth <[EMAIL PROTECTED]> wrote: > Hi R, > > > > Can I transpose a data frame by a particular group variable? > > > > For example: > > d=data.frame(group=c(

Re: [R] Transposing by a group variable

2008-02-14 Thread Dimitris Rizopoulos
try this: d <- data.frame(group = c(1,1,2,2,2), val = c(6,4,6,3,5)) d$time <- unlist(tapply(d$group, d$group, function (x) seq(1, len = length(x reshape(d, idvar = "group", direction = "wide") I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre