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

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


> we have (imported from excel)
> 
> frame <- data.frame("x0"=c("y1","y2","y3","y4"),"x1"=c(1,2,3,4),"x2"=c(5,6,7,8),"x1"=c(9,10,11,12))
> where y1..yn are the names of the rows
> we need  frame$x1   .. .  frame$xn
> and  frame[1,] .. frame[n,]  but the first column is no the rownames.
> 
> if it is possible to rotate the whole dataset we could use
> 
> frame$y1 ..frame$y2

I am not 100% sure I understood what you intend to do but I think what
you are saying is that you would like to address certain rows by name
rather than by index. Is that correct?

If so you could solve it like this:

# assign the desired row names
rownames(frame) = frame[,1]
# remove the old name column
frame <- frame[,2:ncol(frame)]

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