Hi, I have a data matrix with 13 columns and 55 rows. First coulmn is year and other are monthly values for 55 years. Now i want to create a single column of all the values ( i e a single time series column from column 2 to 13 ). Is it the for loop that works here ...how ? or how i can rearrange the data so that it becomes a times series column. hope i made the question clear . thank you, ------------------ "Namaste नमस्ते" Aseem Sharma Graduate Research Assistant Northern Hydrometeorology Group(NHG) Natural Resources and Environmental Studies Institute(NRESi) University of Northern British Columbia Prince George, BC, V2N 4Z9, Canada Tel: 250-960-5427 Web: http://www.unbc.ca/ "All know the Way, but few actually walk it." "सबैको कल्याण होस् ।" [[alternative HTML version deleted]]
Hi, Aseem, you may want to look at ?stack or ?reshape (and transform your matrix into a data frame). Hth -- Gerrit On Wed, 2 Jan 2013, Aseem Sharma wrote:> Hi, > I have a data matrix with 13 columns and 55 rows. First coulmn is year and > other are monthly values for 55 years. > Now i want to create a single column of all the values ( i e a single time > series column from column 2 to 13 ). > Is it the for loop that works here ...how ? > or how i can rearrange the data so that it becomes a times series column. > hope i made the question clear . > thank you, > > > ------------------ > > "Namaste ??????????????????" > > Aseem Sharma > > Graduate Research Assistant > > Northern Hydrometeorology Group(NHG) > > Natural Resources and Environmental Studies Institute(NRESi) > > University of Northern British Columbia > > Prince George, BC, V2N 4Z9, Canada > > Tel: 250-960-5427 > > Web: http://www.unbc.ca/ > > > "All know the Way, but few actually walk it." > "??????????????? ?????????????????? ???????????? ???" > > [[alternative HTML version deleted]]
On 01/03/2013 04:00 PM, Aseem Sharma wrote:> Hi, > I have a data matrix with 13 columns and 55 rows. First coulmn is year and > other are monthly values for 55 years. > Now i want to create a single column of all the values ( i e a single time > series column from column 2 to 13 ). > Is it the for loop that works here ...how ? > or how i can rearrange the data so that it becomes a times series column. > hope i made the question clear . > thank you, > >Hi Aseem, This is a "reshape" problem. There is a "reshape" function in the stats package that comes with R that will do this. Say your data frame is named "mydata" and the columns are named "year" and "Jan" to "Dec": reshape(mydata,varying=month.abb,v.names="month", timevar="year",direction="long") Jim
On 01/03/2013 09:07 PM, Jim Lemon wrote:> On 01/03/2013 04:00 PM, Aseem Sharma wrote: >> Hi, >> I have a data matrix with 13 columns and 55 rows. First coulmn is year >> and >> other are monthly values for 55 years. >> Now i want to create a single column of all the values ( i e a single >> time >> series column from column 2 to 13 ). >> Is it the for loop that works here ...how ? >> or how i can rearrange the data so that it becomes a times series column. >> hope i made the question clear . >> thank you, >> >> > Hi Aseem, > This is a "reshape" problem. There is a "reshape" function in the stats > package that comes with R that will do this. Say your data frame is > named "mydata" and the columns are named "year" and "Jan" to "Dec": > > reshape(mydata,varying=month.abb,v.names="month", > timevar="year",direction="long") >Or, now that I think of it: library(prettyR) rep_n_stack(mydata,to.stack=month.abb,stack.names=c("month","value")) Jim