You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: NEWS.md
+45-1Lines changed: 45 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -246,7 +246,51 @@
246
246
#9: 2025-09-22 9 8 9.0
247
247
```
248
248
249
-
19.Newrollingfunctions, `frollmin`and`frollprod`, havebeenimplemented, towards [#2778](https://github.com/Rdatatable/data.table/issues/2778). Thanks to @jangorecki for implementation.
249
+
19.Newrollingfunctions:`frollmin`, `frollprod`and`frollmedian`, havebeenimplemented, towards [#2778](https://github.com/Rdatatable/data.table/issues/2778). Thanks to @jangorecki for implementation. Implementation of rolling median is based on a novel algorithm "sort-median" described by [@suomela](https://github.com/suomela) in 2014 in his paper [Median Filtering is Equivalent to Sorting](https://arxiv.org/abs/1406.1717). "sort-median" scales very well, not only for size of input vector but also for size of rolling window.
250
+
```r
251
+
rollmedian=function(x, n) {
252
+
ans= rep(NA_real_, nx<-length(x))
253
+
if (n<=nx) for (iinn:nx) ans[i] = median(x[(i-n+1L):(i)])
254
+
ans
255
+
}
256
+
library(data.table)
257
+
setDTthreads(8)
258
+
set.seed(108)
259
+
x= rnorm(1e5)
260
+
261
+
n=100
262
+
system.time(rollmedian(x, n))
263
+
# user system elapsed
264
+
# 2.049 0.001 2.051
265
+
system.time(frollapply(x, n, median, simplify=unlist))
266
+
# user system elapsed
267
+
# 3.071 0.223 0.436
268
+
system.time(frollmedian(x, n))
269
+
# user system elapsed
270
+
# 0.013 0.000 0.004
271
+
272
+
n=1000
273
+
system.time(rollmedian(x, n))
274
+
# user system elapsed
275
+
# 3.496 0.009 3.507
276
+
system.time(frollapply(x, n, median, simplify=unlist))
277
+
# user system elapsed
278
+
# 4.552 0.307 0.632
279
+
system.time(frollmedian(x, n))
280
+
# user system elapsed
281
+
# 0.015 0.000 0.004
282
+
283
+
n=10000
284
+
system.time(rollmedian(x, n))
285
+
# user system elapsed
286
+
# 16.350 0.025 16.382
287
+
system.time(frollapply(x, n, median, simplify=unlist))
\href{https://en.wikipedia.org/wiki/Round-off_error}{Round-off error}, \href{https://arxiv.org/abs/1406.1717}{"Median Filtering is Equivalent to Sorting" by Jukka Suomela}
//void frolladaptivemedianFast(const double *x, uint64_t nx, ans_t *ans, const int *k, double fill, bool narm, int hasnf, bool verbose); // does not exists as of now
0 commit comments