Re: [R] stacking consecutive columns

2010-11-18 Thread peter dalgaard
On Nov 17, 2010, at 16:37 , Graves, Gregory wrote: Follows is the exact solution to this: v - NULL #note that decreasing is FALSE so preceding year preceeds for(i in 2:46) { kk - melt(yearmonth[, c(1, i, i+1)], id.vars=month, variable_name=year) v[[i-1]] - kk[order(kk$year,

Re: [R] stacking consecutive columns

2010-11-18 Thread Gabor Grothendieck
On Wed, Nov 17, 2010 at 10:37 AM, Graves, Gregory ggra...@sfwmd.gov wrote: Follows is the exact solution to this: v - NULL #note that decreasing is FALSE so preceding year preceeds for(i in 2:46) {  kk - melt(yearmonth[, c(1, i, i+1)], id.vars=month, variable_name=year)  v[[i-1]] -

Re: [R] stacking consecutive columns

2010-11-17 Thread Dimitris Rizopoulos
one approach is the following: # say 'Data' is your data frame DataNew - reshape(Data, direction = long, varying = list(2:length(Data))) DataNew$year - rep(2000:2009, each = 12) DataNew I hope it helps. Best, Dimitris On 11/17/2010 3:03 PM, Graves, Gregory wrote: I have a file, each column

Re: [R] stacking consecutive columns

2010-11-17 Thread Claudia Beleites
Dear Gregory, Is there an easier, cleaner way to do this? Thanks. There are of course several ways... (assuming yearmonth to be a data.frame) --- 1 --- year - colnames (yearmonth) [-1] year - gsub (^[^[:digit:]]*([[:digit:]]*[^[:digit:]]*$), \\1, year) year - as.numeric (year) month -

Re: [R] stacking consecutive columns

2010-11-17 Thread Patrick Hausmann
Hi Gregory, is this what you want? Ok, not the most elegant way... # using 'melt' from the 'reshape' package library(reshape) Data - data.frame(month = 1:12, x2002 = runif(12), x2003 = runif(12), x2004 = runif(12), x2005 =

Re: [R] stacking consecutive columns

2010-11-17 Thread Graves, Gregory
Management District Phones:  DESK: 561 / 682 - 2429       CELL:  561 / 719 - 8157 -Original Message- From: Patrick Hausmann [mailto:patrick.hausm...@uni-bremen.de] Sent: Wednesday, November 17, 2010 9:49 AM To: r-help@r-project.org; Graves, Gregory Subject: Re: [R] stacking

Re: [R] stacking consecutive columns

2010-11-17 Thread Graves, Gregory
-Original Message- From: Patrick Hausmann [mailto:patrick.hausm...@uni-bremen.de] Sent: Wednesday, November 17, 2010 9:49 AM To: r-help@r-project.org; Graves, Gregory Subject: Re: [R] stacking consecutive columns Hi Gregory, is this what you want? Ok, not the most elegant way

Re: [R] stacking consecutive columns

2010-11-17 Thread David Winsemius
On Nov 17, 2010, at 10:37 AM, Graves, Gregory wrote: Follows is the exact solution to this: v - NULL #note that decreasing is FALSE so preceding year preceeds for(i in 2:46) { kk - melt(yearmonth[, c(1, i, i+1)], id.vars=month, variable_name=year) v[[i-1]] - kk[order(kk$year,