[R] reshaping a data frame

John Kane jrkrideau at yahoo.ca
Mon Oct 26 23:01:58 CET 2009


Why not just unlist the data.frame and specify the number of rows in a matrix each time you need look at a different layout, assuming I understand the question.

Example
===================================================================

aa <- data.frame(1:100)
bb <- unlist(aa)
(cc <- matrix(bb, nrow=20))

====================================================================

--- On Mon, 10/26/09, Erin Hodgess <erinm.hodgess at gmail.com> wrote:

> From: Erin Hodgess <erinm.hodgess at gmail.com>
> Subject: [R]  reshaping a data frame
> To: "R help" <r-help at stat.math.ethz.ch>
> Received: Monday, October 26, 2009, 4:09 PM
> Dear R People:
> 
> Suppose I have a data.frame, x.df, which has one column and
> 100 rows.
> 
> Sometimes I need to see it as 20 rows and 5 columns,
> sometimes I need
> to see it as 10 rows with 10 columns.
> 
> Is there a quick way to make those transformations,
> please?
> 
> Thanks in advance,
> Sincerely,
> Erin
[[elided Yahoo spam]]
> 
> 
> -- 
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: erinm.hodgess at gmail.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.
> 


      __________________________________________________________________
[[elided Yahoo spam]]




More information about the R-help mailing list