[R] Assigning fate percent to plots
    David Winsemius 
    dwinsemius at comcast.net
       
    Wed Jul 15 22:34:46 CEST 2015
    
    
  
On Jul 15, 2015, at 12:12 PM, Robin Gropp wrote:
> Hi.
> 
> I have a big data set which could be represented something like this:
> 
> *plot     fate*
> 1         S
> 2         M
> 3         S
> 3         S
> 3         M
> 4         S
> 4         S
> 5         S
> 5         M
> 5         S
> 5         S
> 6         M
> 7         M
> 
> where plot is a location, and fate is either "survivorship" or "mortality"
> ( a plant lives or dies.) Thus in plot 5 there are 4 plants. 3 of them
> survive, 1 dies.
> I want to figure out a way to make R calculate the fraction of individuals
> that survive in each plot for all of these. It is proving very challenging.
> 
> Example: Plot 5 would return a survivorship value of 3/4 or 75%/
>                Plot 3 would return a survivorship value of 2/3 or 66%
Divide the survivors by the number at risk.
tdat <- with( dat, table(plot, fate) )  # a matrix-like object
tdat[,'S']/rowSums(tdat)
        1         2         3         4         5         6 
1.0000000 0.0000000 0.6666667 1.0000000 0.7500000 0.0000000 
        7 
0.0000000 
> 
> Any help would be much appreciated.
> Thank you
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
David Winsemius
Alameda, CA, USA
    
    
More information about the R-help
mailing list