fill | R Documentation |
The function will loop through a vector and will substitute NA
values with the value it last encountered or replaced.
fill(x, forward = TRUE, inc = 0)
x |
|
forward |
|
inc |
|
NA
s won't be substituted when they are the first values the loop encounters.
A logical vector.
# forward, replace with previous
dummy<- c(TRUE, FALSE, NA, TRUE, FALSE, NA)
fill(dummy)
# forward, replace with previous+1
dummy2 <- c(1,NA, 3, 1, 2, NA, NA, 9, NA,3)
fill(dummy2, inc=1)
# backward, replace with previous in loop direction
fill(dummy2, inc=0, forward=FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.