[R-sig-eco] help with script

Tom_Philippi at nps.gov Tom_Philippi at nps.gov
Thu Aug 11 20:01:34 CEST 2011


Katia--

One approach would be to order the dataframe by subparcel and (decreasing)
diameter within subparcels. then use tapply or aggregate to compute
cumulative sums of diameters within each subparcel.

If you have lots of ties, that approach would give the individuals (trees?)
random order within a size, so one is treated as if it is the largest, the
next gets the first included in the cumulative sum but not any others, etc.
If you want each tie to include diameters of all other individuals of the
same size, you'll need to run a second pass taking max by subparcel &
diameter.

Something like (untested code):
df <- df[order(df$subparcel,-1*df$diameter),]   # sort by
df$CumBigger <- aggregate(diameter~subparcel,data=df,FUN=cumsum)

MaxDia <- agregate(CumBigger~subparcel+diameter,data=df,FUN=max)
df$CumBigger <-
MaxDia$CumBigger[df$subparcel==MaxDia$subparcel&df$diameter==MaxDia$diameter]

Tom

-------------------------------------------
Tom Philippi, Ph.D.
Quantitative Ecologist
Inventory and Monitoring Program
National Park Service
c/o Cabrillo National Monument
1800 Cabrillo Memorial Dr
San Diego, CA 92106
(619) 523-4562
Tom_philippi at NPS.gov
http://science.nature.nps.gov/im/monitor
-------------------------------------------



                                                                           
             Kátia Emidio                                                  
             <kat.emidio at gmail                                             
             .com>                                                      To 
             Sent by:                  "r-sig-ecology at r-project.org\""     
             r-sig-ecology-bou         <r-sig-ecology at r-project.org>       
             nces at r-project.or                                          cc 
             g                                                             
                                                                   Subject 
                                       [R-sig-eco] help with script        
             08/11/2011 01:44                                              
             PM AST                                                        
                                                                           
                                                                           
                                                                           
                                                                           




Dear all,
Attached there is a table, with columns "subparcel", "nrindividual",
"diameter".
Within each subparcel, for each "nrindividual" I need to sum up the
diameter
of others "nrindividuals"  lying in the subparcel, which "diameter" is
larger than or equal the fixed "nrindividual", excluding the diameter of
the  fixed individual.
To summarize, I need to visit each individual inside the subparcel and find
the others individuals in the same sub-parcel that have the diameter larger
than or equal the visited individual and sum their diameter and return
these
information in a table, having "visited individual", "Subparcel", "diameter
sum". I also need to perform these for n subparcels!
Thanks!

Katia Emidio
[attachment "table.txt" deleted by Tom Philippi/FTCOLLINS/NPS]
_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology



More information about the R-sig-ecology mailing list