Calculate time series frequency and proportion
calc_ts_np.Rd
Calculate time series frequency and proportion
Value
A tibble with 4 columns
* `time`: the time variable
* `varname`: the variable to compute
* `n`: frequency of each category of `varname` per time step
* `prop`: proportion of each category of `varname` per time step
Author
Thinh Ong https://github.com/thinhong
Examples
df <- patients
calc_ts_np(data = df, varname = age_class, time = onset_month)
#> # A tibble: 190 × 4
#> # Groups: onset_month [30]
#> onset_month age_class n prop
#> <date> <fct> <int> <dbl>
#> 1 2017-07-01 [12,18) 1 0.333
#> 2 2017-07-01 [18,24) 2 0.667
#> 3 2017-08-01 [6,9) 2 0.222
#> 4 2017-08-01 [12,18) 2 0.222
#> 5 2017-08-01 [18,24) 4 0.444
#> 6 2017-08-01 [24,Inf) 1 0.111
#> 7 2017-09-01 [0,3) 1 0.0417
#> 8 2017-09-01 [3,6) 2 0.0833
#> 9 2017-09-01 [6,9) 5 0.208
#> 10 2017-09-01 [9,12) 4 0.167
#> # ℹ 180 more rows