Skip to content

Commit d3f08f3

Browse files
Improve description of nan= and fill= in ?nafill, include example (#7186)
* Improve description of nan= * Also clarify how fill= works in locf * Also link ?fcoalesce
1 parent 3bb2e76 commit d3f08f3

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

man/nafill.Rd

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
Fast fill missing values using constant value, \emph{last observation carried forward} or \emph{next observation carried backward}.
1111
}
1212
\usage{
13-
nafill(x, type=c("const","locf","nocb"), fill=NA, nan=NA)
14-
setnafill(x, type=c("const","locf","nocb"), fill=NA, nan=NA, cols=seq_along(x))
13+
nafill(x, type=c("const", "locf", "nocb"), fill=NA, nan=NA)
14+
setnafill(x, type=c("const", "locf", "nocb"), fill=NA, nan=NA, cols=seq_along(x))
1515
}
1616
\arguments{
17-
\item{x}{ vector, list, data.frame or data.table of numeric columns. }
18-
\item{type}{ character, one of \emph{"const"}, \emph{"locf"} or \emph{"nocb"}. Defaults to \code{"const"}. }
19-
\item{fill}{ numeric or integer, value to be used to fill. }
20-
\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? }
21-
\item{cols}{ numeric or character vector specifying columns to be updated. }
17+
\item{x}{ Vector, list, data.frame or data.table of numeric columns. }
18+
\item{type}{ Character, one of \emph{"const"}, \emph{"locf"} or \emph{"nocb"}. Defaults to \code{"const"}. }
19+
\item{fill}{ Numeric value to be used to replace missing observations. See examples. }
20+
\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. }
21+
\item{cols}{ Numeric or character vector specifying columns to be updated. }
2222
}
2323
\details{
2424
Only \emph{double} and \emph{integer} data types are currently supported.
@@ -33,13 +33,21 @@ x = 1:10
3333
x[c(1:2, 5:6, 9:10)] = NA
3434
nafill(x, "locf")
3535

36+
x = c(1, NA, NaN, 3, NaN, NA, 4)
37+
nafill(x, "locf")
38+
nafill(x, "locf", nan=NaN)
39+
40+
# fill= applies to any leftover NA
41+
nafill(c(NA, x), "locf")
42+
nafill(c(NA, x), "locf", fill=0)
43+
3644
dt = data.table(v1=x, v2=shift(x)/2, v3=shift(x, -1L)/2)
3745
nafill(dt, "nocb")
3846

3947
setnafill(dt, "locf", cols=c("v2","v3"))
4048
dt
4149
}
4250
\seealso{
43-
\code{\link{shift}}, \code{\link{data.table}}
51+
\code{\link{shift}}, \code{\link{data.table}}, \code{\link{fcoalesce}}
4452
}
4553
\keyword{ data }

0 commit comments

Comments
 (0)