Re: [R] Help with reshape/reShape and indexing

2009-05-13 Thread Dana Sevak
To all of you who answered me: Thank you so much! Each approach taught me something new and I really appreciate your help! Best regards, Dana Sevak __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the pos

Re: [R] Help with reshape/reShape and indexing

2009-05-13 Thread hadley wickham
> This does it more or less your way: > > ds <- split(df, df$Name) > ds <- lapply(ds, function(x){x$Index <- seq_along(x[,1]); x}) > df2 <- unsplit(ds, df$Name) > tapply(df2$X1, df2[,c("Name", "Index")], function(x) x) > > athough there may exist much easier ways ... Here's one way with the plyr a

Re: [R] Help with reshape/reShape and indexing

2009-05-13 Thread Gabor Grothendieck
Try this: DF$Index <- ave(1:nrow(DF), DF$Name, FUN = seq_along) reshape(DF[-3], dir = "wide", idvar = "Name", timevar = "Index") Also see the reshape package for another similar facility. On Wed, May 13, 2009 at 2:02 AM, Dana Sevak wrote: > > Dear R Helpers, > > I have trouble applying reShap

Re: [R] Help with reshape/reShape and indexing

2009-05-13 Thread Dimitris Rizopoulos
one way is the following: df.index <- df df.index$Index <- ave(seq_along(df$Name), df$Name, FUN = seq_along) df.index df2 <- reshape(df.index[c("Name", "Index", "X1")], timevar = "Index", idvar = "Name", direction = "wide") df2 I hope it helps. Best, Dimitris Dana Sevak wrote: Dear R Hel

Re: [R] Help with reshape/reShape and indexing

2009-05-13 Thread Uwe Ligges
Dana Sevak wrote: Dear R Helpers, I have trouble applying reShape and reshape although I read the documentation and several posts, so I would very much appreciate your help on the two points below. I have a dataframe df = data.frame(Name=c("a", "a", "a", "b", "b", "c"), X1=c("12", "13", "1