Re: [R] help for reshape function

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Thu, 17 Jun 2010 17:26:46 -0300

Try this:

 reshape(x, direction = 'long', varying = list(3:5), timevar = "gene", v.names = "value")

On Thu, Jun 17, 2010 at 3:22 PM, xin wei <xinwei_at_stat.psu.edu> wrote:

>
> 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.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]


______________________________________________ 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:29:04 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 Fri 18 Jun 2010 - 05:50:33 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