[R] to extract extreme data for specified period

David Winsemius dwinsemius at comcast.net
Tue Jun 17 21:55:07 CEST 2014


On Jun 16, 2014, at 11:51 PM, dila radi wrote:

> Dear R users,
> 
> I used this codes to find the 1-day annual rainfall maximum
> 
> bmFort <- blockmaxxer(Fort, blocks = Fort$year, which="Prec");bmFort
> 
> and the output is given below:
> 
> structure(list(obs = c(119, 507, 994, 1398, 1583, 1917), tobs = c(119,
> 142, 264, 303, 123, 91), month = c(4, 5, 9, 10, 5, 4), day = c(29,
> 22, 21, 30, 2, 1), year = c(1900, 1901, 1902, 1903, 1904, 1905
> ), Prec = c(2.39, 2.32, 4.34, 0.85, 3.02, 1.74)), .Names = c("obs",
> "tobs", "month", "day", "year", "Prec"), row.names = c(119L,
> 507L, 994L, 1398L, 1583L, 1917L), class = "data.frame")
> 
> however, I would also like to find the 7-days annual rainfall maximum by
> months within a year. I tried changing ' Fort$year' to ' Fort$day' and I
> got the following:
> 
> structure(list(obs = c(28610, 1583, 14125, 18052, 18905, 32937
> ), tobs = c(121, 123, 246, 155, 278, 65), month = c(5, 5, 9,
> 6, 10, 3), day = c(1, 2, 3, 4, 5, 6), year = c(1978, 1904, 1938,
> 1949, 1951, 1990), Prec = c(1.85, 3.02, 3.54, 3.54, 1.67, 3.48
> )), .Names = c("obs", "tobs", "month", "day", "year", "Prec"), row.names =
> c(28610L,
> 1583L, 14125L, 18052L, 18905L, 32937L), class = "data.frame")
> 
> what I want is the 7-days maximum within a year that is maximum value for
> eg. from 1/1/1990 to 7/1/1990 then another maximum is 8/1/1990 to 14/1/1990
> and so on.
> 
> this is some sample data:
> structure(list(obs = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
> 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
> 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40), tobs = c(1,
> 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
> 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
> 36, 37, 38, 39, 40), month = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 2, 2, 2, 2, 2, 2, 2, 2, 2), day = c(1, 2, 3, 4, 5, 6, 7, 8, 9,
> 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
> 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9), year = c(1900,
> 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900,
> 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900,
> 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900,
> 1900, 1900, 1900, 1900, 1900, 1900), Prec = c(0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.1, 0.03, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0.08, 0.04, 0, 0, 0, 0, 0, 0, 0, 0, 0.02, 0, 0)), .Names =
> c("obs",
> "tobs", "month", "day", "year", "Prec"), row.names = c(NA, 40L
> ), class = "data.frame")
> 
> Thank you very much for any help given.

There is a `cut` method for datetime objects.  You don't yet seem to have your data in a Date-classed column, but after you did so, it would be fairly easy to use that function. It is only set up to start weeks with Sunday or Monday boundaries. Your problem specification seems difficult to implement since you want weekly maxima within months. Why would that no be just monthly maxima?

?cut.POSIXt

> cut(as.Date("2000/01/01")+0:60, breaks="week")
 [1] 1999-12-27 1999-12-27 2000-01-03 2000-01-03 2000-01-03 2000-01-03 2000-01-03 2000-01-03
 [9] 2000-01-03 2000-01-10 2000-01-10 2000-01-10 2000-01-10 2000-01-10 2000-01-10 2000-01-10
[17] 2000-01-17 2000-01-17 2000-01-17 2000-01-17 2000-01-17 2000-01-17 2000-01-17 2000-01-24
[25] 2000-01-24 2000-01-24 2000-01-24 2000-01-24 2000-01-24 2000-01-24 2000-01-31 2000-01-31
[33] 2000-01-31 2000-01-31 2000-01-31 2000-01-31 2000-01-31 2000-02-07 2000-02-07 2000-02-07
[41] 2000-02-07 2000-02-07 2000-02-07 2000-02-07 2000-02-14 2000-02-14 2000-02-14 2000-02-14
[49] 2000-02-14 2000-02-14 2000-02-14 2000-02-21 2000-02-21 2000-02-21 2000-02-21 2000-02-21
[57] 2000-02-21 2000-02-21 2000-02-28 2000-02-28 2000-02-28
10 Levels: 1999-12-27 2000-01-03 2000-01-10 2000-01-17 2000-01-24 2000-01-31 ... 2000-02-28


> 
> Dila
> 
> 	[[alternative HTML version deleted]]

This is a plain text mailing list.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> 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