Hi Henrique, *Thank you!* The reshape code does precisely what I want. Cheers!! Albert-Jan
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In the face of ambiguity, refuse the temptation to guess. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- On Tue, 3/2/10, Henrique Dallazuanna <www...@gmail.com> wrote: From: Henrique Dallazuanna <www...@gmail.com> Subject: Re: [R] simple data transformation question To: "Albert-Jan Roskam" <fo...@yahoo.com> Cc: r-help@r-project.org Date: Tuesday, March 2, 2010, 2:45 PM Try this: reshape(cbind(id = as.numeric(dtf$var), dtf, time = with(dtf, ave(value, var, FUN = seq))), timevar="time", direction="wide") Or: xtabs(value ~ var + ave(value, var, FUN = seq), data = dtf) On Tue, Mar 2, 2010 at 9:40 AM, Albert-Jan Roskam <fo...@yahoo.com> wrote: > Hi all, > I have a (hopefully) simple newbie-level question. > > # I have data like this: > dtf <- data.frame(read.table(textConnection("var value > company 9887.1 > company 91117.0 > blaah 91.1 > etc 11 > etc 97111"), header=TRUE)) > > # I would like to have output like this (the index number may vary): > var value.1 value.2 > company 9887.1 91117.0 > blah 91.1 NA > etc 11 97111 > > # I tried the following. > library(reshape) > cast(dtf, var~value, mean) # 'mean' because some function needs to be > specified. > ... this does not what I want, nor does t(dtf). > > Can somebody help me with the correct transformation, or at least with which > function to use best? Thank you in advance! > > Cheers!! > Albert-Jan > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > In the face of ambiguity, refuse the temptation to guess. > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.