lapply
不能按預期工作。我得到了以下功能:帶lapply和seq_along的矩陣索引
testing <- function(x){
x <- lapply(seq_along(x), function(i) x[[i]][,2] <- c(88,88,88))
return(x)
}
和測試矩陣的列表:
xl <- list(matrix(1:9,3,3),matrix(2:10,3,3))
輸出爲:
[[1]]
[1] 88 88 88
[[2]]
[1] 88 88 88
爲什麼會出現這種情況?我預計第二列將被88個替代,而不是由88個向量替代的矩陣。我必須在這裏錯過一些東西。
@Frank感謝,編輯。 – EDC