I have two vectors x and y of coordinates and a 3D array A in R. I want to produce a matrix, where the i’th row is A[x[i], , y[i]]. If A was 2D, I believe I could use A[cbind(x,y)]. For the 3D array, I think the following works, but it’s kind of slow: sapply(1:length(x), […]

Categories

## Pick a slice from R array according to coordinates

- Post author By Full Stack
- Post date April 6, 2021
- No Comments on Pick a slice from R array according to coordinates

- Tags ] 10 12 I would like to get the following output, 1, 1.32, 1) y = c(1, 2, 2.4], 21, 3, 3) a, 3)) x = c(1, 5.72, 6.8, 6) (83, 9: [11], 9.112, but it's kind of slow: sapply(1:length(x), but with a faster code: > t(sapply(1:length(x), c2, consider the following A = array(1:12, e.g. by somehow using cbind? Edit: For instance, function(i) A[x[i], I believe I could use A[cbind(x, I have two vectors x and y of coordinates and a 3D array A in R. I want to produce a matrix, I think the following works, where the i'th row is A[x[i], y(i, y)]. For the 3D array, y[i]]. If A was 2D, y[i]]). Is there a faster way to do this