[R] reshape a matrix

Uwe Ligges ligges at statistik.tu-dortmund.de
Sat Aug 20 18:32:52 CEST 2011



On 20.08.2011 17:04, Wendy wrote:
> Hi all,
>
> I have a data.frame like following
>
> A<-c('d0','d0','d1','d1','d2','d2')
> B<-rep(c('control','sample'),3)
> C<-c(rep(100000,2),200,300,400,500)
> dataframe<-data.frame(A,B,C)
>
> I want to reshape the matrix, so the matrix with 'd0', 'd1' and 'd2' in rows
> and 'control' and 'sample' in columns. Is there a function for doing this
> easily?

See ?reshape

reshape(data=dataframe, idvar="A", timevar="B", direction="wide")

Uwe Ligges




>
> Thank you in advance.
>
> Wendy
>
> --
> View this message in context: http://r.789695.n4.nabble.com/reshape-a-matrix-tp3757179p3757179.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list