I have daily data, and I would like to count the number of times a year when the daily measurement is in a certain range. Data is also grouped by coefficient, so I need to know the number of days per year for each factor that is in a certain range (for example, from 15 to 18).
I have a large dataset for over 100 years, but here are some data just for this example:
Date <- seq(as.Date("2010/01/01"), by = "day", length.out = 1095)
People <- sample.int(20, 1095, replace = TRUE)
Country <- sample(x = c("Australia", "Canada", "France"), size = 1095, replace = TRUE)
mydf <- data.frame(Date, People, Country)
I would like to know how many times a year the value of "People" is from 15 to 18 for each country.
Thus, my output will be a new data framework, for example:
myDate People Country
2010 45 Australia
2010 10 Canada
2010 24 France
2011 33 Australia
2011 100 Canada
2011 4 France
2012 21 Australia
2012 66 Canada
2012 211 France
, , , .