Message-ID: <50E55A9C.8090002@bitwrit.com.au>
Date: 2013-01-03T10:17:00Z
From: Jim Lemon
Subject: Make a column from columns
In-Reply-To: <50E55869.5000200@bitwrit.com.au>
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