whichDim | R Documentation |
can determine the array-'position' of an element number
whichDim(element, dimensions)
element |
integer coming usually coming from which(...). Note: can only be a single number |
dimensions |
dimensions of the (multidimensional) array from which the element comes |
array with position of the element
based on multi.which by M vd Loo, 2011
https://www.r-bloggers.com/2011/09/a-multidimensional-which-function/
example code: set.seed(83) ar3 <- array(rbinom(20,1,0.5), dim = c(4,5)) ar3
ar3[1,1] <- 2 ar3[2,1] <- 2 ar3[1,2] <- 2 ar3[3,4] <- 2 ar3[2,5] <- 2 ar3[4,5] <- 2
ar3
which(ar3 == 2) multi.which(ar3 == 2) whichDim(20, dimensions = dim(ar3)) # to get positions of all elements that are 2 purrr::map_df(which(ar3 == 2), ~as.data.frame(whichDim(.x, dimensions = dim(ar3))))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.