Description Usage Arguments Details Examples
given NA values fill them with the final non-na value
1 | fill_forward(x)
|
x |
A numeric vector of values |
Works very well in context of dplyr to carry out last-observation-carried-foward for different individuals. It will NOT replace leading NA's
1 2 3 4 5 | fill_forward(c(1.0, NA, 2))
fill_forward(c(NA, 1, NA, 2))
library(dplyr)
df <- data_frame(id = c(1, 1, 2, 2), obs = c(1.2, 4.8, 2.5, NA))
df %>% group_by(id) %>% mutate(obs_locf = fill_forward(obs))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.