Re: [R] How to obtain a mean by more than one other variable

2014-03-10 Thread arun


Hi,
If `dat` is the dataset:

with(dat,ave(ABUNDHA,SITE,REP,FUN=mean))
#[1] 0.46 0.46 0.14 0.03 0.22 0.67 0.01

I am not sure how you got 0.45 when REP's are not the same.

A.K.

On Sunday, March 9, 2014 11:29 PM, Erynn Call erynn.c...@maine.edu wrote:
I'm trying to create a new variable (meanABUNDHA) by obtaining a mean value
*by* other variables.  I surveyed birds (multiple species) at multiple sites
and have multiple surveys within a REP (i.e. in example data below, SURVEY
55 and 57 are in REP 11).  I need the mean ABUNDHA (pooling SURVEY) for each
BIRD species by REP and by SITE. Below, I would average 0.77 and 0.15 for
MALL in REP 11 at SITE 1 to get 0.46 meanABUNDHA.

An example of my data are as follows, including the new variable I hope to
create meanABUNDHA:
SITE    REP     SURVEY  BIRD    ABUNDHA meanABUNDHA
1       11            57             MALL      0.77            0.46
1       11            55             MALL      0.15            0.46
1       12            58             MALL      0.14            0.14
1       2              58             BAEA     0.03            0.03
3       4              64             AMCR     0.22            0.45
3       5              65             AMCR     0.67            0.45
7       11             56             MALL      0.01            0.01

I'm not sure how to incorporate more than one by=?

data.all4[,mean(ABUNDHA),by=
REP]

#Add new column containing the by-REP mean of ABUNDHA
data.all5-data.all4[,ABUNDHAmean:=mean(ABUNDHA),by=REP]

Thank you for any guidance!!

    [[alternative HTML version deleted]]

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


[R] How to obtain a mean by more than one other variable

2014-03-09 Thread Erynn Call
I'm trying to create a new variable (meanABUNDHA) by obtaining a mean value
*by* other variables.  I surveyed birds (multiple species) at multiple sites
and have multiple surveys within a REP (i.e. in example data below, SURVEY
55 and 57 are in REP 11).  I need the mean ABUNDHA (pooling SURVEY) for each
BIRD species by REP and by SITE. Below, I would average 0.77 and 0.15 for
MALL in REP 11 at SITE 1 to get 0.46 meanABUNDHA.

An example of my data are as follows, including the new variable I hope to
create meanABUNDHA:
SITEREP SURVEY  BIRDABUNDHA meanABUNDHA
1   1157 MALL  0.770.46
1   1155 MALL  0.150.46
1   1258 MALL  0.140.14
1   2  58 BAEA 0.030.03
3   4  64 AMCR 0.220.45
3   5  65 AMCR 0.670.45
7   11 56 MALL  0.010.01

I'm not sure how to incorporate more than one by=?

data.all4[,mean(ABUNDHA),by=
REP]

#Add new column containing the by-REP mean of ABUNDHA
data.all5-data.all4[,ABUNDHAmean:=mean(ABUNDHA),by=REP]

Thank you for any guidance!!

[[alternative HTML version deleted]]

__
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] How to obtain a mean by more than one other variable

2014-03-09 Thread Peter Alspach
Tena koe Erynn

Have you checked tapply and aggregate?

HTH 

Peter Alspach

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Erynn Call
Sent: Monday, 10 March 2014 3:40 p.m.
To: r-help@r-project.org
Subject: [R] How to obtain a mean by more than one other variable

I'm trying to create a new variable (meanABUNDHA) by obtaining a mean value
*by* other variables.  I surveyed birds (multiple species) at multiple sites 
and have multiple surveys within a REP (i.e. in example data below, SURVEY
55 and 57 are in REP 11).  I need the mean ABUNDHA (pooling SURVEY) for each 
BIRD species by REP and by SITE. Below, I would average 0.77 and 0.15 for MALL 
in REP 11 at SITE 1 to get 0.46 meanABUNDHA.

An example of my data are as follows, including the new variable I hope to 
create meanABUNDHA:
SITEREP SURVEY  BIRDABUNDHA meanABUNDHA
1   1157 MALL  0.770.46
1   1155 MALL  0.150.46
1   1258 MALL  0.140.14
1   2  58 BAEA 0.030.03
3   4  64 AMCR 0.220.45
3   5  65 AMCR 0.670.45
7   11 56 MALL  0.010.01

I'm not sure how to incorporate more than one by=?

data.all4[,mean(ABUNDHA),by=
REP]

#Add new column containing the by-REP mean of ABUNDHA 
data.all5-data.all4[,ABUNDHAmean:=mean(ABUNDHA),by=REP]

Thank you for any guidance!!

[[alternative HTML version deleted]]

__
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 contents of this e-mail are confidential and may be ...{{dropped:14}}

__
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] How to obtain a mean by more than one other variable

2014-03-09 Thread Andrew Koeser

One function I like is from package psych.

library(psych)
describe.by(ARK$TotalWater, group=Tray:Pot)

Andrew Koeser

On 3/9/2014 10:39 PM, Erynn Call wrote:

I'm trying to create a new variable (meanABUNDHA) by obtaining a mean value
*by* other variables.  I surveyed birds (multiple species) at multiple sites
and have multiple surveys within a REP (i.e. in example data below, SURVEY
55 and 57 are in REP 11).  I need the mean ABUNDHA (pooling SURVEY) for each
BIRD species by REP and by SITE. Below, I would average 0.77 and 0.15 for
MALL in REP 11 at SITE 1 to get 0.46 meanABUNDHA.

An example of my data are as follows, including the new variable I hope to
create meanABUNDHA:
SITEREP SURVEY  BIRDABUNDHA meanABUNDHA
1   1157 MALL  0.770.46
1   1155 MALL  0.150.46
1   1258 MALL  0.140.14
1   2  58 BAEA 0.030.03
3   4  64 AMCR 0.220.45
3   5  65 AMCR 0.670.45
7   11 56 MALL  0.010.01

I'm not sure how to incorporate more than one by=?

data.all4[,mean(ABUNDHA),by=
REP]

#Add new column containing the by-REP mean of ABUNDHA
data.all5-data.all4[,ABUNDHAmean:=mean(ABUNDHA),by=REP]

Thank you for any guidance!!

[[alternative HTML version deleted]]

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



--
Andrew Koeser, BCMA, Ph.D.
Assistant Professor of Landscape Management
University of Florida - Gulf Coast Research and Education Center
813-633-4150

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