Here is an example where I act on a given column of every data frame stored in a list. I just did a simple multiplication but using na_kalman should be very similar. Just write
DF$Sediment <- na_kalman(DF$Sediment, model = "StructTS", smooth = TRUE, maxgap = Inf)
instead of my multiplication step.
library(tidyverse)
#> Warning: package 'tibble' was built under R version 4.1.2
DF1 <- data.frame(Year = 2020:2022,
Discharge = c(3,5,4), Sediment = c(5,7,6))
DF2 <- data.frame(Year = 2020:2022,
Discharge = c(5,2,3), Sediment = c(6,4,7))
DF1 <- data.frame(Year = 2020:2022,
Discharge = c(3,5,4), Sediment = c(5,7,6))
np = list(A = DF1, B = DF2)
np
#> $A
#> Year Discharge Sediment
#> 1 2020 3 5
#> 2 2021 5 7
#> 3 2022 4 6
#>
#> $B
#> Year Discharge Sediment
#> 1 2020 5 6
#> 2 2021 2 4
#> 3 2022 3 7
ExmplFunc <- function(DF) {
DF$Discharge <- DF$Discharge * 2
return(DF)
}
np2 <- map(np, ExmplFunc)
np2
#> $A
#> Year Discharge Sediment
#> 1 2020 6 5
#> 2 2021 10 7
#> 3 2022 8 6
#>
#> $B
#> Year Discharge Sediment
#> 1 2020 10 6
#> 2 2021 4 4
#> 3 2022 6 7
Created on 2022-03-28 by the reprex package (v2.0.1)