[R] read.xls -> rotate data.frame

Philipp Pagel p.pagel at wzw.tum.de
Fri Mar 25 12:31:07 CET 2011


On Fri, Mar 25, 2011 at 11:43:31AM +0100, Knut Krueger wrote:
> Hi to all,
> how could I  to rotate automatically a data sheet which was imported
> by read.xls?
> 
>      x1 x2 x3 .... xn
> y1 1   4  7   ...  xn/y1
> y2 2   5  8   .... xn/y2
> y3 3   6  9    ....xn/y2
> yn ... ... ...         Xn/Yn
> 
> 
> to
> 
>       y1 y2  y3   ....  yn
> x1  1  2    3     ..... Yn/x1
> x2  4  5    6     ....  Yn/x2
> x3  7  8   9      ....  Yn/x2
> xn  ...   ...  ...   .....  Yn/xn

If all the columns (x) are of the same type (e.g. all numeric) you can
use t(). Example:

dat <- data.frame(x1=1:10, x2=(1:10)*2, x3=10:1)
dat2 <- as.data.frame(t(dat))

If the comlumns are of differnt types (e.g. some numeric, some
factors) I don't think you can do this at all, because columns of a
data.frame represent vectors, i.e. all value sin a column need to be
of the same type.

cu
	Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
Maximus-von-Imhof-Forum 3
85354 Freising, Germany
http://webclu.bio.wzw.tum.de/~pagel/



More information about the R-help mailing list