How to do a "proc summary" in R?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to do a "proc summary" in R?

Emilie Berthiaume
Hi,

I'm a SAS user trying to convert myself to R but I still have problems with some pretty simple commands.

First I wanted to add up a number of red-tailed hawks seen per day (julian day) per year.  So I tried:

RTyrday <- tapply(RThr,list(year,julian),sum)

And then I tried the following regression:

mod1 <-  glm(RTyrday~julian+year, family=gaussian (link=identity),data=RT)

Wich didn't work since my vector RTyrday and julian don't have the same length.  My question is: How can I create a new data sheet with the output of my function "tapply" ?  Something I could have done in SAS by giving an "output out" to my "proc summary"

Thank you,

Emilie



Emilie Berthiaume
Graduate Student
Biology Department
Sherbooke University
Sherbrooke, Québec
CANADA

[hidden email]
        [[alternative HTML version deleted]]


______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How to do a "proc summary" in R?

Kjetil Halvorsen
Emilie Berthiaume wrote:
> Hi,
>
> I'm a SAS user trying to convert myself to R but I still have problems with some

pretty simple commands.
>
> First I wanted to add up a number of red-tailed hawks seen per day (

julian day) per year.  So I tried:
>
> RTyrday <- tapply(RThr,list(year,julian),sum)

Try:

RT <- as.data.frame.table(RTyrday)


>
> And then I tried the following regression:
>
> mod1 <-  glm(RTyrday~julian+year, family=gaussian (link=identity),data=RT)

here it is simpler with lm()

Kjetil

>
> Wich didn't work since my vector RTyrday and julian don't have the same length.  My question is: How can I create a new data sheet with the output of my function "tapply" ?  Something I could have done in SAS by giving an "output out" to my "proc summary"
>
> Thank you,
>
> Emilie
>
>
>
> Emilie Berthiaume
> Graduate Student
> Biology Department
> Sherbooke University
> Sherbrooke, Québec
> CANADA
>
> [hidden email]
> [[alternative HTML version deleted]]
>
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How to do a "proc summary" in R?

Frank Harrell
In reply to this post by Emilie Berthiaume
Emilie Berthiaume wrote:

> Hi,
>
> I'm a SAS user trying to convert myself to R but I still have problems with some pretty simple commands.
>
> First I wanted to add up a number of red-tailed hawks seen per day (julian day) per year.  So I tried:
>
> RTyrday <- tapply(RThr,list(year,julian),sum)
>
> And then I tried the following regression:
>
> mod1 <-  glm(RTyrday~julian+year, family=gaussian (link=identity),data=RT)
>
> Wich didn't work since my vector RTyrday and julian don't have the same length.  My question is: How can I create a new data sheet with the output of my function "tapply" ?  Something I could have done in SAS by giving an "output out" to my "proc summary"
>
> Thank you,
>
> Emilie

One of many ways is at
http://biostat.mc.vanderbilt.edu/SasByMeansExample (especially for SAS
users).  The example uses the R Hmisc package.

Frank

>
>
>
> Emilie Berthiaume
> Graduate Student
> Biology Department
> Sherbooke University
> Sherbrooke, Québec
> CANADA
>
> [hidden email]
> [[alternative HTML version deleted]]
>
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


--
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Frank Harrell
Department of Biostatistics, Vanderbilt University
Reply | Threaded
Open this post in threaded view
|

Re: "proc summary" in R?: follow up

Frank Harrell
Emilie Berthiaume wrote:

>
> I found out that for want I want to do I must use the function
> "summarize". My only problem now is that I don't understand how to
> summarize two vectors at a time.  For exemple, I wanted to get the sum
> of RThr and effortwt per day per year so I've tried this:
>
> RTyrday <- with(RT.sub,summarize(cbind(RThr,effortwt),
> llist(year,jjulian), FUN=sum))
>
> But the output combine RThr and effortwt instead of doing two separate
> column with those vectors.
> What am I missing?
>
> Thanks for your help,
>
> Emilie

See the example I posted 2 hours ago, especially how you need to specify
FUN.

FH

>
> ----- Original Message ----- From: "Frank E Harrell Jr"
> <[hidden email]>
> To: "Emilie Berthiaume" <[hidden email]>
> Cc: <[hidden email]>
> Sent: Wednesday, March 01, 2006 12:16 PM
> Subject: Re: [R] How to do a "proc summary" in R?
>
>
> Emilie Berthiaume wrote:
>
>> Hi,
>>
>> I'm a SAS user trying to convert myself to R but I still have problems
>> with some pretty simple commands.
>>
>> First I wanted to add up a number of red-tailed hawks seen per day
>> (julian day) per year.  So I tried:
>>
>> RTyrday <- tapply(RThr,list(year,julian),sum)
>>
>> And then I tried the following regression:
>>
>> mod1 <-  glm(RTyrday~julian+year, family=gaussian
>> (link=identity),data=RT)
>>
>> Wich didn't work since my vector RTyrday and julian don't have the
>> same length.  My question is: How can I create a new data sheet with
>> the output of my function "tapply" ?  Something I could have done in
>> SAS by giving an "output out" to my "proc summary"
>>
>> Thank you,
>>
>> Emilie
>
>
> One of many ways is at
> http://biostat.mc.vanderbilt.edu/SasByMeansExample (especially for SAS
> users).  The example uses the R Hmisc package.
>
> Frank
>
>>
>>
>>
>> Emilie Berthiaume
>> Graduate Student
>> Biology Department
>> Sherbooke University
>> Sherbrooke, Québec
>> CANADA
>>
>> [hidden email]
>> [[alternative HTML version deleted]]
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>
>
>


--
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Frank Harrell
Department of Biostatistics, Vanderbilt University