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

Rich Shepard r@hep@rd @ending from @ppl-eco@y@@com
Mon Sep 17 02:30:32 CEST 2018


On Sun, 16 Sep 2018, Gabriel Gaona wrote:

> An other option is the tydiverse way. I assume when you say " My goal is to
> use the monthly mean rainfall at each of the 58 reporting stations..." you
> mean you want for each year and station a average value of monthly prcp .
>> From your input data frame, is like:
>
> library(dplyr)
> library(lubridate)
> rainfall_yearly <- rainfall %>%
>    group_by(name,
>        Month = floor_date(sampdate, "month")) %>% #Monthly round down
> dates for grouping
>    summarise(prcp = sum(prcp, na.rm = TRUE) %>% #calculating monthly prcp
>    group_by(name,
>        Year = floor_date(Month, "year")) %>% #Yearly round down dates for
> grouping
>    summarise(prcp = mean(prcp, na.rm = TRUE) #calculating monthly average
> per year

Gabriel,

   Thank you very much I'm learning a lot from all the responses.

Best regards,

Rich



More information about the R-sig-Geo mailing list