Arguments
- .data
data frame
- .group
group variable
- ...
variables to be filled. If no variables were provided, the function will fill in missing values for all variables.
Examples
data.frame(
var1 = c(NA,2,3,NA),
var2 = c(NA,NA,3,3),
var3 = c(NA,1,3,3),
var4 = c(10,NA, 2,NA),
group = c(1,1,2,2)
) -> data
fill_by_group(data, group, var1, var3)
#> # A tibble: 4 × 5
#> var1 var2 var3 var4 group
#> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 2 NA 1 10 1
#> 2 2 NA 1 NA 1
#> 3 3 3 3 2 2
#> 4 3 3 3 NA 2