Вот один вариант без инициализации матрицы
out <- Reduce(`+`, lapply(list.data, function(x) x * NA^!m ))/2
replace(out, is.na(out), list.data[[1]][is.na(out)])
# V1 V2
#[1,] -1.8526984 -0.5701164
#[2,] -0.3826858 -1.4453051
#[3,] 0.9963491 -0.2830805
#[4,] 0.7020922 -0.7633606
#[5,] -0.1454009 0.7233905
или в одну строку с coalesce
library(dplyr)
coalesce(Reduce(`+`, lapply(list.data, function(x) x * NA^!m ))/2, list.data[[1]])
или то же самое в трубе
library(tidyverse)
library(magrittr)
map(list.data, ~ .x * NA^ !m ) %>%
reduce(`+`) %>%
divide_by(2) %>%
coalesce(list.data[[1]])
данные
list.data <- list(df1 = structure(c(-1.8526984, -0.9391172, 0.2793443,
2.0174213,
0.2100461, -1.3359316, -1.4453051, -1.0223621, -1.1734235, -0.1261543
), .Dim = c(5L, 2L), .Dimnames = list(NULL, c("V1", "V2"))),
df2 = structure(c(-1.8526984, 0.1737456, 1.7133539, -0.6132369,
-0.5008479, 0.1956987, -1.4453051, 0.4562011, -0.3532976,
1.5729352), .Dim = c(5L, 2L), .Dimnames = list(NULL, c("V1",
"V2"))))
m <- structure(c(FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE,
TRUE, TRUE), .Dim = c(5L, 2L))