Based on base::cut(). Allows to specifiy maximum wind velocity. If squish = TRUE the values greater than ws_max
will be combined to one additional factor level ">ws_max". If squish = FALSE the resulting vector will contain
NA for this values. The correct handling of the NA values in the factor must be done by the user.
Usage
cut_ws(
  ws,
  binwidth = 1,
  ws_max = NA,
  squish = TRUE,
  right = TRUE,
  reverse = FALSE,
  calm = NA
)Arguments
- ws
 numeric vector of wind velocity
- binwidth
 width of the bins
- ws_max
 cut off wind speed at this maximum
- squish
 If TRUE wind velocities greater than will be include as additional level ">ws_max"
- right
 logical, indicating if the intervals should be closed on the right (and open on the left) or vice versa.
- reverse
 reverse order of result. This is sometimes useful when plotting a factor.
- calm
 threshold for calm wind situation. All windspeed below this limit will be assigned the the factor level "calm".
Examples
ws <- c(0.3, 1.1, 2.2, 3.3, 4.4, 5, 8.8)
cut_ws(ws, binwidth = 2)
#> [1] [0,2]  [0,2]  (2,4]  (2,4]  (4,6]  (4,6]  (8,10]
#> Levels: [0,2] < (2,4] < (4,6] < (6,8] < (8,10]
# if ws_max not a multiple of binwidth, the last level before squishing will be cut short
cut_ws(ws, binwidth = 2, ws_max = 5)
#> [1] [0,2] [0,2] (2,4] (2,4] >4    >4    >4   
#> Levels: [0,2] < (2,4] < >4
# calm support: all wind speed below threshold will be gathered in the class calm
cut_ws(ws, ws_max = 5, calm = 0.5)
#> [1] calm  (1,2] (2,3] (3,4] (4,5] (4,5] >5   
#> Levels: calm < (0.5,1] < (1,2] < (2,3] < (3,4] < (4,5] < >5
cut_ws(ws, binwidth = 2, ws_max = 5, squish = FALSE)
#> Maximum greater than cut off value. Squishing data
#> [1] [0,2] [0,2] (2,4] (2,4] >4    >4    >4   
#> Levels: [0,2] < (2,4] < >4
# close the intervals on the left side
# unfortunately there is a issue in converting the console output to
# html: the unicode character for >= gets scrambled to =
# https://github.com/r-lib/evaluate/issues/59
cut_ws(ws, binwidth = 2, ws_max = 5, right = FALSE)
#> [1] [0,2) [0,2) [2,4) [2,4) ≥4    ≥4    ≥4   
#> Levels: [0,2) < [2,4) < ≥4
# reverse the order of the factors, useful for legends while plotting
cut_ws(ws, binwidth = 2, ws_max = 5, reverse = TRUE)
#> [1] [0,2] [0,2] (2,4] (2,4] >4    >4    >4   
#> Levels: >4 < (2,4] < [0,2]
