Assume your dataframe is called df
, your variables are called Hs
and Direction
, you can use
max(df$Hs[df$Direction >= 11.25 & df$Direction <= 33.75])
to get the maximum of all Hs
values within the defined value range of Direction
.
If you, like me, dislike the necessity to define both lower and upper bounds of the interval separately, you can use this neat function (which I found here):
in_interval <- function(x, interval){
stopifnot(length(interval) == 2L)
interval[1] < x & x < interval[2]
}
Then use
max(df$Hs[in_interval(df$Direction, c(11.25, 33.75))])
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…