From 038ae8f9fe021c4064112535328376f58b0edbbb Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 17 Jul 2025 09:16:13 -0700 Subject: [PATCH 1/3] Improve description of nan= --- man/nafill.Rd | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/man/nafill.Rd b/man/nafill.Rd index 480f6ae118..54c5623673 100644 --- a/man/nafill.Rd +++ b/man/nafill.Rd @@ -14,11 +14,11 @@ 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 numeric columns. } - \item{type}{ character, one of \emph{"const"}, \emph{"locf"} or \emph{"nocb"}. Defaults to \code{"const"}. } - \item{fill}{ numeric or integer, value to be used to fill. } - \item{nan}{ (numeric \code{x} only) 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? } - \item{cols}{ numeric or character vector specifying columns to be updated. } + \item{x}{ Vector, list, data.frame or data.table of numeric columns. } + \item{type}{ Character, one of \emph{"const"}, \emph{"locf"} or \emph{"nocb"}. Defaults to \code{"const"}. } + \item{fill}{ Double or integer, value to be used to fill. } + \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. } + \item{cols}{ Numeric or character vector specifying columns to be updated. } } \details{ Only \emph{double} and \emph{integer} data types are currently supported. @@ -33,6 +33,10 @@ x = 1:10 x[c(1:2, 5:6, 9:10)] = NA nafill(x, "locf") +x = c(1, NA, NaN, 3, NaN, NA, 4) +nafill(x, "locf") +nafill(x, "locf", nan=NaN) + dt = data.table(v1=x, v2=shift(x)/2, v3=shift(x, -1L)/2) nafill(dt, "nocb") From f0ed80b6d047f6a44379c717eea089c98e4a91d5 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 17 Jul 2025 09:24:21 -0700 Subject: [PATCH 2/3] Also clarify how fill= works in locf --- man/nafill.Rd | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/man/nafill.Rd b/man/nafill.Rd index 54c5623673..94f3a9e619 100644 --- a/man/nafill.Rd +++ b/man/nafill.Rd @@ -16,7 +16,7 @@ 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 numeric columns. } \item{type}{ Character, one of \emph{"const"}, \emph{"locf"} or \emph{"nocb"}. Defaults to \code{"const"}. } - \item{fill}{ Double or integer, value to be used to fill. } + \item{fill}{ Numeric 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. } \item{cols}{ Numeric or character vector specifying columns to be updated. } } @@ -37,6 +37,10 @@ x = c(1, NA, NaN, 3, NaN, NA, 4) nafill(x, "locf") nafill(x, "locf", nan=NaN) +# fill= applies to any leftover NA +nafill(c(NA, x), "locf") +nafill(c(NA, x), "locf", fill=0) + dt = data.table(v1=x, v2=shift(x)/2, v3=shift(x, -1L)/2) nafill(dt, "nocb") From 06bf1b42a6df16c7c687e1c523ab8c195b20ad26 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 17 Jul 2025 09:30:30 -0700 Subject: [PATCH 3/3] Also link ?fcoalesce --- man/nafill.Rd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/man/nafill.Rd b/man/nafill.Rd index 94f3a9e619..7c3433d2d3 100644 --- a/man/nafill.Rd +++ b/man/nafill.Rd @@ -10,8 +10,8 @@ Fast fill missing values using constant value, \emph{last observation carried forward} or \emph{next observation carried backward}. } \usage{ -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)) +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 numeric columns. } @@ -48,6 +48,6 @@ setnafill(dt, "locf", cols=c("v2","v3")) dt } \seealso{ - \code{\link{shift}}, \code{\link{data.table}} + \code{\link{shift}}, \code{\link{data.table}}, \code{\link{fcoalesce}} } \keyword{ data }