How can one loop through multiple data sets in R, it seems a little elusive from Python.
We have 4 lists and want to simply remove all missing values.
Example:
a <- c(1,2,3, NA)
b <- c(1,NA,3, NA)
e <- c(1,2,3, 4)
f <- c(NA,2,3, NA)
is.na(a_df) ## -> TRUE
na_list = list(a, b, e, f)
What has been tried:
- Duplicating the code 4 times, which is DRY but works.
for (lst in na_list){
lst <- zoo::na.aggregate(lst)
}
- Using Lappy
na_list <- lapply(na_list, zoo::na.aggregate)
> na_list
[[1]]
[1] 1 2 3 2
[[2]]
[1] 1 2 3 2
but..
> a
[1] 1 2 3 NA