|
32 | 32 | ``` |
33 | 33 | Additionally argument names in `frollapply` has been renamed from `x` to `X` and `n` to `N` to avoid conflicts with common argument names that may be passed to `...`, aligning to base R API of `lapply`. `x` and `n` continue to work with a warning, for now. |
34 | 34 |
|
| 35 | +5. Adaptive rolling functions no longer tolerate `NA`s and negative values passed to `n` argument. |
| 36 | + ```r |
| 37 | + n = c(2,NA,2) |
| 38 | + frollsum(1:3, n, adaptive=TRUE) |
| 39 | + #Error in froll(fun = "sum", x = x, n = n, fill = fill, algo = algo, align = align, : |
| 40 | + # 'n' must be non-negative integer values (>= 0) |
| 41 | + ``` |
| 42 | + If for some reason previous `NA`s behavior is needed, it can be achieved by replacing `NA`s with a value big enough |
| 43 | + ```r |
| 44 | + n = nafill(c(2,NA,2), fill=.Machine$integer.max) |
| 45 | + frollsum(1:3, n, adaptive=TRUE) |
| 46 | + ``` |
| 47 | +
|
35 | 48 | ### NOTICE OF INTENDED FUTURE POTENTIAL BREAKING CHANGES |
36 | 49 |
|
37 | 50 | 1. `data.table(x=1, <expr>)`, where `<expr>` is an expression resulting in a 1-column matrix without column names, will eventually have names `x` and `V2`, not `x` and `V1`, consistent with `data.table(x=1, <expr>)` where `<expr>` results in an atomic vector, for example `data.table(x=1, cbind(1))` and `data.table(x=1, 1)` will both have columns named `x` and `V2`. In this release, the matrix case continues to be named `V1`, but the new behavior can be activated by setting `options(datatable.old.matrix.autoname)` to `FALSE`. See point 5 under Bug Fixes for more context; this change will provide more internal consistency as well as more consistency with `data.frame()`. |
|
210 | 223 | #[1] TRUE |
211 | 224 | ``` |
212 | 225 |
|
| 226 | +18. New `frolladapt` helper function has been added to aid in preparation of adaptive length of rolling window width when dealing with _irregularly spaced ordered data_. This lets the user to apply a rolling function over a period without having to deal with gaps in a data where some periods might be missing. |
| 227 | +```r |
| 228 | +idx = as.Date("2022-10-23") + c(0,1,4,5,6,7,9,10,14) |
| 229 | +dt = data.table(index=idx, value=seq_along(idx)) |
| 230 | +dt |
| 231 | +# index value |
| 232 | +# <Date> <int> |
| 233 | +#1: 2022-10-23 1 |
| 234 | +#2: 2022-10-24 2 |
| 235 | +#3: 2022-10-27 3 |
| 236 | +#4: 2022-10-28 4 |
| 237 | +#5: 2022-10-29 5 |
| 238 | +#6: 2022-10-30 6 |
| 239 | +#7: 2022-11-01 7 |
| 240 | +#8: 2022-11-02 8 |
| 241 | +#9: 2022-11-06 9 |
| 242 | +dt[, c("rollmean3","rollmean3days") := list( |
| 243 | + frollmean(value, 3), |
| 244 | + frollmean(value, frolladapt(index, 3), adaptive=TRUE) |
| 245 | + )] |
| 246 | +dt |
| 247 | +# index value rollmean3 rollmean3days |
| 248 | +# <Date> <int> <num> <num> |
| 249 | +#1: 2022-10-23 1 NA NA |
| 250 | +#2: 2022-10-24 2 NA NA |
| 251 | +#3: 2022-10-27 3 2 3.0 |
| 252 | +#4: 2022-10-28 4 3 3.5 |
| 253 | +#5: 2022-10-29 5 4 4.0 |
| 254 | +#6: 2022-10-30 6 5 5.0 |
| 255 | +#7: 2022-11-01 7 6 6.5 |
| 256 | +#8: 2022-11-02 8 7 7.5 |
| 257 | +#9: 2022-11-06 9 8 9.0 |
| 258 | +``` |
| 259 | + |
213 | 260 | ### BUG FIXES |
214 | 261 |
|
215 | 262 | 1. `fread()` no longer warns on certain systems on R 4.5.0+ where the file owner can't be resolved, [#6918](https://github.com/Rdatatable/data.table/issues/6918). Thanks @ProfFancyPants for the report and PR. |
|
0 commit comments