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
3333x [c(1 : 2 , 5 : 6 , 9 : 10 )] = NA
3434nafill(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+
3644dt = data.table(v1 = x , v2 = shift(x )/ 2 , v3 = shift(x , - 1L )/ 2 )
3745nafill(dt , " nocb" )
3846
3947setnafill(dt , " locf" , cols = c(" v2" ," v3" ))
4048dt
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