From 2c23421feef4842612630302e8a4c7ed988cea33 Mon Sep 17 00:00:00 2001 From: Leonidas Zhak <70497898+LeonidasZhak@users.noreply.github.com> Date: Sun, 7 Jun 2026 00:33:09 +0800 Subject: [PATCH 1/2] docs: add panel data example to frolladapt.Rd Add a grouped rolling mean example showing frolladapt + frollmean with by= for panel data. This is the data.table equivalent of Stata's rangestat (mean) ..., int(date -2 0) by(firm) for time-aware rolling windows within groups respecting irregular date gaps. --- man/frolladapt.Rd | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/man/frolladapt.Rd b/man/frolladapt.Rd index 2c4d45e7a4..01068081a8 100644 --- a/man/frolladapt.Rd +++ b/man/frolladapt.Rd @@ -35,6 +35,19 @@ dt n34 = frolladapt(idx, c(small=3, big=4), give.names=TRUE) n34 dt[, frollmean(value, n34, adaptive=TRUE, give.names=TRUE)] + +## panel data: rolling mean within groups, respecting irregular date gaps +## equivalent to Stata: rangestat (mean) rollmean3 = sales, int(date -2 0) by(firm) +dt = data.table( + firm = rep(c("A", "B"), each = 4), + date = as.Date(c("2020-01-01", "2020-01-02", "2020-01-05", "2020-01-06", + "2020-01-01", "2020-01-03", "2020-01-04", "2020-01-07")), + sales = c(10, 12, 15, 13, 20, 22, 18, 25) +) +setorder(dt, firm, date) +dt[, rollmean3 := frollmean(sales, frolladapt(date, n=3L, partial=TRUE), + adaptive=TRUE), by = firm] +dt } \seealso{ \code{\link{froll}}, \code{\link{frollapply}} From e0608d8ed2da24ad9aa7a2711bb3e0f93bfb5321 Mon Sep 17 00:00:00 2001 From: Leonidas Zhak <70497898+LeonidasZhak@users.noreply.github.com> Date: Sun, 7 Jun 2026 08:16:59 +0800 Subject: [PATCH 2/2] docs: fix \code{} tag in melt.Rd, add factor to nafill.Rd @param x MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - melt.data.table.Rd:59 — \code{numeric > integer > logical} had broken \code{} tag spanning two lines; each type now wrapped individually - nafill.Rd:17 — @param x listed 'logical, numeric or character' but Details section and examples confirm factor is also supported --- man/melt.data.table.Rd | 3 +-- man/nafill.Rd | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/man/melt.data.table.Rd b/man/melt.data.table.Rd index 40506eb6ab..46f85611d3 100644 --- a/man/melt.data.table.Rd +++ b/man/melt.data.table.Rd @@ -56,8 +56,7 @@ more than once and the same column can be both as id and measure variables. variables. When all \code{measure.vars} are not of the same type, they'll be coerced -according to the hierarchy \code{list} > \code{character} > \code{numeric > -integer > logical}. For example, if any of the measure variables is a +according to the hierarchy \code{list} > \code{character} > \code{numeric} > \code{integer} > \code{logical}. For example, if any of the measure variables is a \code{list}, then entire value column will be coerced to a list. From version \code{1.9.6}, \code{melt} gains a feature with \code{measure.vars} diff --git a/man/nafill.Rd b/man/nafill.Rd index 90c4b1c5c6..659d371e16 100644 --- a/man/nafill.Rd +++ b/man/nafill.Rd @@ -14,7 +14,7 @@ nafill(x, type=c("const", "locf", "nocb"), fill=NA, nan=NA) setnafill(x, type=c("const", "locf", "nocb"), fill=NA, nan=NA, cols=seq_along(x)) } \arguments{ - \item{x}{ Vector, list, data.frame or data.table of logical, numeric or character columns. } + \item{x}{ Vector, list, data.frame or data.table of logical, numeric, character, or factor columns. } \item{type}{ Character, one of \emph{"const"}, \emph{"locf"} or \emph{"nocb"}. Defaults to \code{"const"}. } \item{fill}{ Value to be used to replace missing observations. See examples. } \item{nan}{ Either \code{NaN} or \code{NA}; if the former, \code{NaN} is treated as distinct from \code{NA}, otherwise, they are treated the same during replacement. See Examples. }