Replacing elements of arrays within a list (R)

Okay, here's the situation: I have the following list of arrays: N <- c('A', 'B', 'C') ll <- sapply(N, function(x) NULL) ll <- lapply(ll, function(x) assign("x", array(0, dim = c(2,2)))) . Now I want to replace, say, the element at position [1,1] in those arrays by a given quantity, say 10. What I'm doing, following this question [here](https://stackoverflow.com/questions/8751954/apply-function-for-list-of-arrays). That is, I'm doing the following: x <- lapply(ll, function(x) {x[1,1] <- 10}), which should make x a list of three 2x2 arrays with the [1,1] element equal to 10, all others equal to 0. Instead of that, I'm seeing this: > x <- lapply(ll, function(x) {x[2,1] <- 10}) > x $A [1] 10 $B [1] 10 $C [1] 10 Any ideas of what's going on here?

以上就是Replacing elements of arrays within a list (R)的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏