# Get Indices of Specified Values of an Array in R Programming – arrayInd() Function

`arrayInd()` function in R Language is used to get the indices of the values passed to the function as argument. This function takes values and the array in which the values are to be searched and returns the indices for each match found.

Syntax: arrayInd(values, dim(x))

Parameters:
values: value or vector of values to be searched
dim(x): array to be searched
x: Array name

Example 1:

 `# R program to illustrate  ` `# the use of arrayInd() function ` ` `  `# Creating an array ` `x <``-` `array(``1``:``9``, dim ``=` `c(``2``, ``3``))  ` `x ` ` `  `# Creating vector of values to be found ` `x1 <``-` `c(``5``, ``4``, ``6``) ` ` `  `# Calling arrayInd() function ` `arrayInd(x1, dim(x)) `

Output:

```     [, 1] [, 2] [, 3]
[1, ]    1    3    5
[2, ]    2    4    6
[, 1] [, 2]
[1, ]    1    3
[2, ]    2    2
[3, ]    2    3
```

Example 2:

 `# R program to illustrate  ` `# the use of arrayInd() function ` ` `  `# Creating an array ` `x <``-` `array(``1``:``9``, dim ``=` `c(``3``, ``3``))  ` `x ` ` `  `# Extracting values using which() function ` `x1 <``-` `which(x > ``3` `& x < ``8``) ` ` `  `# Calling arrayInd() function ` `arrayInd(x1, dim(x)) `

Output:

```
[, 1] [, 2] [, 3]
[1, ]    1    4    7
[2, ]    2    5    8
[3, ]    3    6    9
[, 1] [, 2]
[1, ]    1    2
[2, ]    2    2
[3, ]    3    2
[4, ]    1    3
```

Here, in tonhte above code, the `arrayInd()` function returns the indices of all the values which were returned by the `which()` function.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.