How to index a multidimensional R array dynamically?

前端 未结 3 390
我寻月下人不归
我寻月下人不归 2021-01-20 12:52

I am working on some data in R that consist of four-dimensional arrays composed of three spatial dimensions and a time dimension: x, y, z, t. For some of my analyses, I woul

3条回答
  •  再見小時候
    2021-01-20 13:18

    I think you are looking for:

    apply(a4d, 4, `[`, indices)
    

    And to check that our results match:

    result1 <- matrix(result[,5], ncol = 10)
    result2 <- apply(a4d, 4, `[`, indices)
    identical(result1, result2)
    # [1] TRUE
    

提交回复
热议问题