My advice is to avoid using outlet names. Rownames are difficult to manage because one variable (rowname) is handled differently than others. This violates the principles of accurate data .
dplyr::add_rownames(), :
library(dplyr)
< >
mat1 <- matrix(1:6, ncol = 1, dimnames = list(letters[1:6]))
mat2 <- matrix(1:4, ncol = 1, dimnames = list(c("x", "a", "y", "b")))
data.frame :
d1 <- add_rownames(data.frame(mat1), var = "name")
d2 <- add_rownames(data.frame(mat2), var = "name")
:
d <- merge(d1, d2, by = "name", all = TRUE)
d %>%
rowwise() %>%
mutate(result = sum(mat1, -mat2, na.rm = TRUE))