powered by
Fast fill missing values using constant value, last observation carried forward or next observation carried backward.
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))
vector, list, data.frame or data.table of numeric columns.
character, one of "const", "locf" or "nocb". Defaults to "const".
"const"
numeric or integer, value to be used to fill when type=="const".
type=="const"
(numeric x only) Either NaN or NA; if the former, NaN is treated as distinct from NA, otherwise, they are treated the same during replacement?
x
NaN
NA
numeric or character vector specifying columns to be updated.
A list except when the input is a vector in which case a vector is returned. For setnafill the input argument is returned, updated by reference.
vector
setnafill
Only double and integer data types are currently supported.
Note that both nafill and setnafill provide some verbose output when getOption('datatable.verbose') is TRUE.
nafill
getOption('datatable.verbose')
TRUE
shift, data.table
shift
data.table
# NOT RUN { x = 1:10 x[c(1:2, 5:6, 9:10)] = NA nafill(x, "locf") dt = data.table(v1=x, v2=shift(x)/2, v3=shift(x, -1L)/2) nafill(dt, "nocb") setnafill(dt, "locf", cols=c("v2","v3")) dt # }
Run the code above in your browser using DataLab