I used the solution in this thread assign dimnames to a list of matrices in R but I didn't get what I need.
I have a list of 4 matrices that I wanted to name their columns and rows the same.
A = list(a = matrix(1:4, 2), b = matrix(2:5, 2))
G = list(a = matrix(10:13, 2), b = matrix(5:8, 2))
M_1 = list(a = matrix(10:13, 2), b = matrix(5:8, 2))
M_2 = list(a = matrix(2:5, 2), b = matrix(5:8, 2))
dlist4 <- tibble::lst(A, G, M_1, M_2)
Map(function(x) {dimnames(x) <- list(c("seed","plant"), c("seed","plant")); x}, dlist4)
and
lapply(dlist4, function(x) {dimnames(x) = list(c("seed","plant"), c("seed","plant")); x})
returned the same error: Error in dimnames(x) <- list(c("seed", "plant"), c("seed", "plant")) : 'dimnames' applied to non-array
I tried the loop
here R: change column names of every matrix in a list, too but it didn't work.
for(i in seq_along(dlist4)) {
dimnames(dlist4[[i]]) <- list(c("seed","plant"), c("seed","plant"))
}
Error in dimnames(dlist4[[i]]) <- list(c("seed", "plant"), c("seed", "plant")) : 'dimnames' applied to non-array