3

I have a very large array (RFO_2003; dim = c(360, 180, 13, 12)) of numeric data. I made the array using a for-loop that does some calculations based another array. I am trying to check some samples of data in this array to ensure I have generated it properly.

To do this, I want to apply a function that returns the index of the array where that element equals a specific value. For example, I want to start by looking at a few examples where the value == 100.

I tried

which(RFO_2003 == 100)

That returned (first line of results)

[1]  459766  460208  460212 1177802 1241374 1241498 1241499 1241711 1241736 1302164 1302165

match gave the same results. What I was expecting was something more like

[8, 20, 3, 6], [12, 150, 4, 7], [16, 170, 4, 8] 

Is there a way to get the indices in that format?

My searches have found solutions in other languages, lots of stuff on vectors, or the index is never output, it is immediately fed into another part of a custom function so I can't see which part would output the index in a way I understand, such as this question, although that one also returns dimnames not an index.

The_Tams
  • 205
  • 1
  • 10
  • 4
    Maybe `which(RFO_2003 == 100, arr.index=TRUE)`? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Nov 24 '21 at 18:58
  • I got the error Error in which(RFO_2003 == 100, arr.index = TRUE) : unused argument (arr.index = TRUE) I will go work out a small example it would work on and add it to the question now. – The_Tams Nov 24 '21 at 19:08
  • 3
    Oops, it's actually `which(RFO_2003 == 100, arr.ind=TRUE)` ("ind", not "index") – MrFlick Nov 24 '21 at 19:09
  • Great, that did just what I needed! – The_Tams Nov 24 '21 at 19:20

0 Answers0