how to extract 1x1 array slice as matrix in R?

后端 未结 2 801

I am working with 3D arrays. A function takes a 2D array slice (matrix) from the user and visualizes it, using row and column names (the corresponding dimnames of the array

相关标签:
2条回答
  • 2021-01-19 11:34

    Without any extra packages, the best I could do was to apply and return the sub-array:

    apply(a, 1:2, identity)
    # or
    apply(a, 1:2, I)
    
    #   B
    #A   b
    #  a 1
    
    0 讨论(0)
  • 2021-01-19 11:48

    The drop parameter of [ is all-or-nothing, but the abind package has an adrop function which will let you choose which dimension you want to drop:

    abind::adrop(a, drop = 3)
    ##    B
    ## A   b
    ##   a 1
    
    0 讨论(0)
提交回复
热议问题