[R] Extracting sums for individual factors in data frames

2007-07-09 Thread Norm.Good
Try this I used today

 

aggregate(data, by=list(factor.name=data$FACTOR.NAME), sum)

 

Norm Good

CMIS/e-Health Research Centre

A joint venture between CSIRO and the Queensland Government

Lvl 20, 300 Adelaide Street BRISBANE QLD 4000
PO Box 10842 Adelaide Street BRISBANE QLD 4000

Ph: 07 3024 1640 Fx: 07 3024 1690 
Em: [EMAIL PROTECTED]  Web: http://e-hrc.net/ 

 


[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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] Extracting sums for individual factors in data frames

2007-07-01 Thread James R. Milks
I have a data frame with two columns, one of which is a factor  
(Species) and the other is numeric (BA, which stands for basal  
area).  Here's a sample:


Species BA
ACSA55.7632696
FRAM122.9933524
ACSA67.54424205
ACSA89.22123136
ACSA82.46680716
ACSA22.46238747
ACSA19.94911335
ACSA20.42035225
ACSA19.00663555
ACSA21.67698931
ACSA57.80530483
ACSA30.31636911
Dead43.98229715
Dead40.21238597
Dead16.49336143
Dead40.21238597
Dead16.49336143
ACSA78.53981634
VIPR3.926990817
AEGL11.78097245
AEGL0
AEGL0
ACSA0
ACSA0
ACSA0
VIPR0

I would like to calculate relative basal area for each species in  
this plot.  For that, I need to divide the total basal area per  
species by the total basal area in the plot.  Getting the total basal  
area in the plot is easy.  However, I'm mystified on how to get the  
total basal area per species.  Is there a way to extract and/or sum  
the total basal area per species?

Thank you in advance.

Jim Milks

Graduate Student
Environmental Sciences Ph.D. Program
Wright State University
3640 Colonel Glenn Hwy
Dayton, OH 45435

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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] Extracting sums for individual factors in data frames

2007-07-01 Thread Rolf Turner

?tapply

##
Attention:\ This e-mail message is privileged and confidenti...{{dropped}}

__
R-help@stat.math.ethz.ch 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] Extracting sums for individual factors in data frames

2007-07-01 Thread jim holtman
Does this do what you want?

 x - Species BA
+ ACSA55.7632696
+ FRAM122.9933524
+ ACSA67.54424205
+ ACSA89.22123136
+ ACSA82.46680716
+ ACSA22.46238747
+ ACSA19.94911335
+ ACSA20.42035225
+ ACSA19.00663555
+ ACSA21.67698931
+ ACSA57.80530483
+ ACSA30.31636911
+ Dead43.98229715
+ Dead40.21238597
+ Dead16.49336143
+ Dead40.21238597
+ Dead16.49336143
+ ACSA78.53981634
+ VIPR3.926990817
+ AEGL11.78097245
+ AEGL0
+ AEGL0
+ ACSA0
+ ACSA0
+ ACSA0
+ VIPR0
 x - read.table(textConnection(x), header=TRUE)
 # compute area for each species
 y - tapply(x$BA, x$Species, sum)
 # get ratio
 y/sum(x$BA)
   ACSAAEGLDeadFRAMVIPR
0.656210104 0.013678643 0.182746672 0.142805034 0.004559548





On 7/1/07, James R. Milks [EMAIL PROTECTED] wrote:

 I have a data frame with two columns, one of which is a factor
 (Species) and the other is numeric (BA, which stands for basal
 area).  Here's a sample:


 Species BA
 ACSA55.7632696
 FRAM122.9933524
 ACSA67.54424205
 ACSA89.22123136
 ACSA82.46680716
 ACSA22.46238747
 ACSA19.94911335
 ACSA20.42035225
 ACSA19.00663555
 ACSA21.67698931
 ACSA57.80530483
 ACSA30.31636911
 Dead43.98229715
 Dead40.21238597
 Dead16.49336143
 Dead40.21238597
 Dead16.49336143
 ACSA78.53981634
 VIPR3.926990817
 AEGL11.78097245
 AEGL0
 AEGL0
 ACSA0
 ACSA0
 ACSA0
 VIPR0

 I would like to calculate relative basal area for each species in
 this plot.  For that, I need to divide the total basal area per
 species by the total basal area in the plot.  Getting the total basal
 area in the plot is easy.  However, I'm mystified on how to get the
 total basal area per species.  Is there a way to extract and/or sum
 the total basal area per species?

 Thank you in advance.

 Jim Milks

 Graduate Student
 Environmental Sciences Ph.D. Program
 Wright State University
 3640 Colonel Glenn Hwy
 Dayton, OH 45435

[[alternative HTML version deleted]]

 __
 R-help@stat.math.ethz.ch 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.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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] Extracting sums for individual factors in data frames

2007-07-01 Thread Simon Blomberg
Does this do what you want?

 with(dat, tapply(BA, Species, sum))
  ACSA   AEGL   Dead   FRAM   VIPR 
565.172518  11.780972 157.393792 122.993352   3.926991 

Cheers,

Simon.

On Sun, 2007-07-01 at 23:15 -0400, James R. Milks wrote:
 I have a data frame with two columns, one of which is a factor  
 (Species) and the other is numeric (BA, which stands for basal  
 area).  Here's a sample:
 
 
 Species   BA
 ACSA  55.7632696
 FRAM  122.9933524
 ACSA  67.54424205
 ACSA  89.22123136
 ACSA  82.46680716
 ACSA  22.46238747
 ACSA  19.94911335
 ACSA  20.42035225
 ACSA  19.00663555
 ACSA  21.67698931
 ACSA  57.80530483
 ACSA  30.31636911
 Dead  43.98229715
 Dead  40.21238597
 Dead  16.49336143
 Dead  40.21238597
 Dead  16.49336143
 ACSA  78.53981634
 VIPR  3.926990817
 AEGL  11.78097245
 AEGL  0
 AEGL  0
 ACSA  0
 ACSA  0
 ACSA  0
 VIPR  0
 
 I would like to calculate relative basal area for each species in  
 this plot.  For that, I need to divide the total basal area per  
 species by the total basal area in the plot.  Getting the total basal  
 area in the plot is easy.  However, I'm mystified on how to get the  
 total basal area per species.  Is there a way to extract and/or sum  
 the total basal area per species?
 
 Thank you in advance.
 
 Jim Milks
 
 Graduate Student
 Environmental Sciences Ph.D. Program
 Wright State University
 3640 Colonel Glenn Hwy
 Dayton, OH 45435
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch 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.
-- 
Simon Blomberg, BSc (Hons), PhD, MAppStat. 
Lecturer and Consultant Statistician 
Faculty of Biological and Chemical Sciences 
The University of Queensland 
St. Lucia Queensland 4072 
Australia

Room 320, Goddard Building (8)
T: +61 7 3365 2506 
email: S.Blomberg1_at_uq.edu.au 

The combination of some data and an aching desire for 
an answer does not ensure that a reasonable answer can 
be extracted from a given body of data. - John Tukey.

__
R-help@stat.math.ethz.ch 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.