[R] transform variables
Jim Lemon
jim at bitwrit.com.au
Mon Aug 26 13:45:01 CEST 2013
On 08/26/2013 09:04 PM, catalin roibu wrote:
> Dear all!
>
> I have a data frame composed by 13 columns (year, and 12 months). I want to
> transform this data base in another like this
> year month values
> 1901 1
> 1901 2
> 1901 3
> .....
> 1901 12
> 1902 1
> 1902 2
> ....
> 1902 12
>
> Is there a possibility to succeed that in R?
>
> Thank you!
>
> best regards!
> CR
>
Hi catalin,
Try this:
yrmon<-data.frame(cbind(1901:1905,matrix(rnorm(60),ncol=12)))
names(yrmon)<-c("year",month.abb)
library(prettyR)
yrmon2<-rep_n_stack(yrmon,to.stack=2:13)
yrmon2[order(yrmon2$year),]
Jim
More information about the R-help
mailing list