Re: [R] SAS user now converting to R - Help with Transpose

2009-09-28 Thread John Kane
library(reshape)
melt(dataset)  # assuming dataset is a data.frame.

--- On Mon, 9/28/09, baxterj  wrote:

> From: baxterj 
> Subject: [R]  SAS user now converting to R - Help with Transpose
> To: r-help@r-project.org
> Received: Monday, September 28, 2009, 10:24 AM
> 
> I am just starting to code in R and need some help as I am
> used to doing this
> in SAS.
> 
> I have a dataset that looks like this:
> 
> Chemical Well1 Well2 Well3 Well4
> BOD 13.2 14.2 15.5 14.2
> O2 7.8 2.6 3.5 2.4
> TURB 10.2 14.6 18.5 17.3
> and so on with more chemicals
> 
> I would like to transpose my data so that it looks like
> this:
> Chemical WellID Value
> BOD Well1 13.2
> BOD Well2 14.2
> BOD Well3 15.5
> BOD Well4 14.2
> O2 Well1 7.8
> O2 Well2 2.6
>  and so on
> 
> In sas I would code it like this:
> proc sort data=ds1; by chemical; run;
> Proc Transpose data=ds1 out=ds2;
> by chemical;
> var Well1 Well2 Well3 Well4;
> run;
> data ds3; set ds2;
> rename _name_ = WellID;
> rename col1 = value;
> run;
> 
> How can I do this in R??  Any help is much
> appreciated.  Thanks!
> -- 
> View this message in context: 
> http://www.nabble.com/SAS-user-now-converting-to-R---Help-with-Transpose-tp25645393p25645393.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@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.
> 


  __
The new Internet Explorer® 8 - Faster, safer, easier.  Optimized for Yaho
__
R-help@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.


Re: [R] SAS user now converting to R - Help with Transpose

2009-09-28 Thread Paul Hiemstra

Hi,

Also take a look at cast(), melt() and recast() from the reshape 
package. Great and very flexible functions.


cheers,
Paul

Daniel Malter schreef:

?reshape

hth,
Daniel


baxterj wrote:
  

I am just starting to code in R and need some help as I am used to doing
this in SAS.

I have a dataset that looks like this:

Chemical Well1 Well2 Well3 Well4
BOD 13.2 14.2 15.5 14.2
O2 7.8 2.6 3.5 2.4
TURB 10.2 14.6 18.5 17.3
and so on with more chemicals

I would like to transpose my data so that it looks like this:
Chemical WellID Value
BOD Well1 13.2
BOD Well2 14.2
BOD Well3 15.5
BOD Well4 14.2
O2 Well1 7.8
O2 Well2 2.6
 and so on

In sas I would code it like this:
proc sort data=ds1; by chemical; run;
Proc Transpose data=ds1 out=ds2;
by chemical;
var Well1 Well2 Well3 Well4;
run;
data ds3; set ds2;
rename _name_ = WellID;
rename col1 = value;
run;

How can I do this in R??  Any help is much appreciated.  Thanks!







__
R-help@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.


Re: [R] SAS user now converting to R - Help with Transpose

2009-09-28 Thread Corrado
I think you want to look at the command "reshape", it may solve your problem.

Type ?reshape in the R console on your system.

On Monday 28 September 2009 18:35:25 Gabor Grothendieck wrote:
> > I have a dataset that looks like this:
> >
> > Chemical Well1 Well2 Well3 Well4
> > BOD 13.2 14.2 15.5 14.2
> > O2 7.8 2.6 3.5 2.4
> > TURB 10.2 14.6 18.5 17.3
> > and so on with more chemicals
> >
> > I would like to transpose my data so that it looks like this:
> > Chemical WellID Value
> > BOD Well1 13.2
> > BOD Well2 14.2
> > BOD Well3 15.5
> > BOD Well4 14.2
> > O2 Well1 7.8
> > O2 Well2 2.6
> >  and so on
> >
> > In sas I would code it like this:
> > proc sort data=ds1; by chemical; run;
> > Proc Transpose data=ds1 out=ds2;
> > by chemical;
> > var Well1 Well2 Well3 Well4;
> > run;
> > data ds3; set ds2;
> > rename _name_ = WellID;
> > rename col1 = value;
> > run;
> >
> > How can I do this in R??  Any help is much appreciated.  Thanks!
> > --
> > View this message in context:
> > http://www.nabble.com/SAS-user-now-converting-to-R---Help-with-Transpose-
> >tp25645393p25645393.html Sent from the R help mailing list archive at
> > Nabble.com.
> >
> > __
> > R-help@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.
>
> __
> R-help@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.



-- 
Corrado Topi

Global Climate Change & Biodiversity Indicators
Area 18,Department of Biology
University of York, York, YO10 5YW, UK
Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk

__
R-help@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.


Re: [R] SAS user now converting to R - Help with Transpose

2009-09-28 Thread Gabor Grothendieck
There is a book called R for SAS and SPSS Users which you might want to look at.

On Mon, Sep 28, 2009 at 10:24 AM, baxterj  wrote:
>
> I am just starting to code in R and need some help as I am used to doing this
> in SAS.
>
> I have a dataset that looks like this:
>
> Chemical Well1 Well2 Well3 Well4
> BOD 13.2 14.2 15.5 14.2
> O2 7.8 2.6 3.5 2.4
> TURB 10.2 14.6 18.5 17.3
> and so on with more chemicals
>
> I would like to transpose my data so that it looks like this:
> Chemical WellID Value
> BOD Well1 13.2
> BOD Well2 14.2
> BOD Well3 15.5
> BOD Well4 14.2
> O2 Well1 7.8
> O2 Well2 2.6
>  and so on
>
> In sas I would code it like this:
> proc sort data=ds1; by chemical; run;
> Proc Transpose data=ds1 out=ds2;
> by chemical;
> var Well1 Well2 Well3 Well4;
> run;
> data ds3; set ds2;
> rename _name_ = WellID;
> rename col1 = value;
> run;
>
> How can I do this in R??  Any help is much appreciated.  Thanks!
> --
> View this message in context: 
> http://www.nabble.com/SAS-user-now-converting-to-R---Help-with-Transpose-tp25645393p25645393.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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.
>

__
R-help@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.


Re: [R] SAS user now converting to R - Help with Transpose

2009-09-28 Thread baxterj

Thank you!  That worked if I coded it like this:

twelldata <- cbind(welldata$Chemical, stack(welldata, names(welldata)))  
names(twelldata)[names(twelldata)=="ind"] <- "WellID"



Henrique Dallazuanna wrote:
> 
> Try this:
> 
> cbind(DF$Chemical, stack(DF, names(DF)))
> 
> On Mon, Sep 28, 2009 at 11:24 AM, baxterj  wrote:
>>
>> I am just starting to code in R and need some help as I am used to doing
>> this
>> in SAS.
>>
>> I have a dataset that looks like this:
>>
>> Chemical Well1 Well2 Well3 Well4
>> BOD 13.2 14.2 15.5 14.2
>> O2 7.8 2.6 3.5 2.4
>> TURB 10.2 14.6 18.5 17.3
>> and so on with more chemicals
>>
>> I would like to transpose my data so that it looks like this:
>> Chemical WellID Value
>> BOD Well1 13.2
>> BOD Well2 14.2
>> BOD Well3 15.5
>> BOD Well4 14.2
>> O2 Well1 7.8
>> O2 Well2 2.6
>>  and so on
>>
>> In sas I would code it like this:
>> proc sort data=ds1; by chemical; run;
>> Proc Transpose data=ds1 out=ds2;
>> by chemical;
>> var Well1 Well2 Well3 Well4;
>> run;
>> data ds3; set ds2;
>> rename _name_ = WellID;
>> rename col1 = value;
>> run;
>>
>> How can I do this in R??  Any help is much appreciated.  Thanks!
>> --
>> View this message in context:
>> http://www.nabble.com/SAS-user-now-converting-to-R---Help-with-Transpose-tp25645393p25645393.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> R-help@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
> 
> __
> R-help@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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/SAS-user-now-converting-to-R---Help-with-Transpose-tp25645393p25649504.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] SAS user now converting to R - Help with Transpose

2009-09-28 Thread Henrique Dallazuanna
Try this:

cbind(DF$Chemical, stack(DF, names(DF)))

On Mon, Sep 28, 2009 at 11:24 AM, baxterj  wrote:
>
> I am just starting to code in R and need some help as I am used to doing this
> in SAS.
>
> I have a dataset that looks like this:
>
> Chemical Well1 Well2 Well3 Well4
> BOD 13.2 14.2 15.5 14.2
> O2 7.8 2.6 3.5 2.4
> TURB 10.2 14.6 18.5 17.3
> and so on with more chemicals
>
> I would like to transpose my data so that it looks like this:
> Chemical WellID Value
> BOD Well1 13.2
> BOD Well2 14.2
> BOD Well3 15.5
> BOD Well4 14.2
> O2 Well1 7.8
> O2 Well2 2.6
>  and so on
>
> In sas I would code it like this:
> proc sort data=ds1; by chemical; run;
> Proc Transpose data=ds1 out=ds2;
> by chemical;
> var Well1 Well2 Well3 Well4;
> run;
> data ds3; set ds2;
> rename _name_ = WellID;
> rename col1 = value;
> run;
>
> How can I do this in R??  Any help is much appreciated.  Thanks!
> --
> View this message in context: 
> http://www.nabble.com/SAS-user-now-converting-to-R---Help-with-Transpose-tp25645393p25645393.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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

__
R-help@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.


[R] SAS user now converting to R - Help with Transpose

2009-09-28 Thread baxterj

I am just starting to code in R and need some help as I am used to doing this
in SAS.

I have a dataset that looks like this:

Chemical Well1 Well2 Well3 Well4
BOD 13.2 14.2 15.5 14.2
O2 7.8 2.6 3.5 2.4
TURB 10.2 14.6 18.5 17.3
and so on with more chemicals

I would like to transpose my data so that it looks like this:
Chemical WellID Value
BOD Well1 13.2
BOD Well2 14.2
BOD Well3 15.5
BOD Well4 14.2
O2 Well1 7.8
O2 Well2 2.6
 and so on

In sas I would code it like this:
proc sort data=ds1; by chemical; run;
Proc Transpose data=ds1 out=ds2;
by chemical;
var Well1 Well2 Well3 Well4;
run;
data ds3; set ds2;
rename _name_ = WellID;
rename col1 = value;
run;

How can I do this in R??  Any help is much appreciated.  Thanks!
-- 
View this message in context: 
http://www.nabble.com/SAS-user-now-converting-to-R---Help-with-Transpose-tp25645393p25645393.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] SAS user now converting to R - Help with Transpose

2009-09-28 Thread Daniel Malter

?reshape

hth,
Daniel


baxterj wrote:
> 
> I am just starting to code in R and need some help as I am used to doing
> this in SAS.
> 
> I have a dataset that looks like this:
> 
> Chemical Well1 Well2 Well3 Well4
> BOD 13.2 14.2 15.5 14.2
> O2 7.8 2.6 3.5 2.4
> TURB 10.2 14.6 18.5 17.3
> and so on with more chemicals
> 
> I would like to transpose my data so that it looks like this:
> Chemical WellID Value
> BOD Well1 13.2
> BOD Well2 14.2
> BOD Well3 15.5
> BOD Well4 14.2
> O2 Well1 7.8
> O2 Well2 2.6
>  and so on
> 
> In sas I would code it like this:
> proc sort data=ds1; by chemical; run;
> Proc Transpose data=ds1 out=ds2;
> by chemical;
> var Well1 Well2 Well3 Well4;
> run;
> data ds3; set ds2;
> rename _name_ = WellID;
> rename col1 = value;
> run;
> 
> How can I do this in R??  Any help is much appreciated.  Thanks!
> 

-- 
View this message in context: 
http://www.nabble.com/SAS-user-now-converting-to-R---Help-with-Transpose-tp25645393p25647137.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.