Subset matrix with arrays in r
问题 It is probably fairly basic but I have not found an easy solution. Assume I have a three-dimensional matrix: m <- array(seq_len(18),dim=c(3,3,2)) and I would like to subset the matrix with the arrays of indexes: idxrows <- c(1,2,3) idxcols <- c(1,1,2) obtaining the arrays in position (1,1) , (2,1) and (3,2) , that is: [,1] [,2] [,3] [1,] 1 5 9 [2,] 10 14 18 I have tried m[idxrows,idxcols,] but without any luck. Is there anyway to do it (without obviously using a for loop)? 回答1: Not sure if