[R-sig-Geo] Subsetting dataframe by all factor levels

Rich Shepard r@hep@rd @ending from @ppl-eco@y@@com
Sat Sep 15 00:19:01 CEST 2018


On Fri, 14 Sep 2018, Justin H. wrote:

> For the sake of example, here's a solution for a simple aggregation.
> rainfall.year<-with(rainfall, tapply(prcp, list(name, year), mean))  #This
> does the aggregation.

Justin,

   The results have sites with 'NA' for the mean precipiation despite having
recorded values some days. For example,

> rainfall.year
                                            0
Blazed Alder                              NA

while

> head(rainfall_by_site[[1]])
              name easting northing   elev   sampdate prcp
7741 Blazed Alder 2393589 196840.8 1112.5 2005-01-01  0.2
7742 Blazed Alder 2393589 196840.8 1112.5 2005-01-02  0.2
7743 Blazed Alder 2393589 196840.8 1112.5 2005-01-03  0.4
7744 Blazed Alder 2393589 196840.8 1112.5 2005-01-04  0.0
7745 Blazed Alder 2393589 196840.8 1112.5 2005-01-05  0.0
7746 Blazed Alder 2393589 196840.8 1112.5 2005-01-06  0.0

   I'll read up on tapply and see if I can identify the reason for the
discrepancy.

Regards,

Rich



More information about the R-sig-Geo mailing list