[R] help for reshape function

From: xin wei <xinwei_at_stat.psu.edu>
Date: Thu, 17 Jun 2010 11:22:30 -0700 (PDT)

hi, everyone:

i have a question on the reshape function. i have the following dataset : gene tissue patient1 patient2 patient3.............


gene1   breast         10       20       50
gene2   breast         20       40       60
gene3   breast         100      200      300

which i hope to convert to the following format:

gene patientID value gene1


gene1   1       10    10
gene1   2       20    20
gene1   3       50    100
gene2   1       20    10
gene2   2       40    20
gene2   3       60    100

the column "gene" is required and column "tissue" is not needed. I use the following syntax to perform this task:

tdata<- reshape(data, varying=names(data)[-c(1,2)],direction="long", timevar ="label",v.names="value",time=names(data)[-c(1,2)]);

however, i lose the column "gene" in the resulting tranposed dataset. I did my best to go through the help doc for reshape. however, I am frustrated that the examples used in the help doc is kind o hard to follow to me. Can anyone help me modify the code to keep the column "gene" in the resulting table?

Any constructive suggestion is welcome. thanks

-- 
View this message in context: http://r.789695.n4.nabble.com/help-for-reshape-function-tp2259286p2259286.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.
Received on Thu 17 Jun 2010 - 20:19:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 Jun 2010 - 20:40:45 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive