function in R Language is used to return the indices of the object which return true for the logical operation passed as argument.**which()**

Syntax:which(x, arr.ind)

Parameters:

x:logical object

arr.ind:Boolean value to display indices

**Example 1:**

`# R program to illustrate ` `# the use of which() function ` ` ` `# Create a matrix ` `x <` `-` `matrix(` `1` `:` `9` `, ` `3` `, ` `3` `) ` `x ` ` ` `# Calling which() function ` `which(x ` `%` `%` `2` `=` `=` `0` `, arr.ind ` `=` `TRUE) ` |

*chevron_right*

*filter_none*

**Output:**

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

Here, in the above code, the `which()`

function returns the indices of all the even numbers present in the matrix.

**Example 2:**

`# R program to illustrate ` `# the use of which() function ` ` ` `# Using predefined dataset ` `BOD ` ` ` `# Calling which() function ` `which(BOD$demand ` `=` `=` `19` `, arr.ind ` `=` `TRUE) ` |

*chevron_right*

*filter_none*

**Output:**

Time demand 1 1 8.3 2 2 10.3 3 3 19.0 4 4 16.0 5 5 15.6 6 7 19.8 [1] 3

## Recommended Posts:

- Return a Matrix with Lower Triangle as TRUE values in R Programming - lower.tri() Function
- Return a Matrix with Upper Triangle as TRUE values in R Programming - upper.tri() Function
- Convert values of an Object to Logical Vector in R Programming - as.logical() Function
- Check if a value or a logical expression is TRUE in R Programming - isTRUE() Function
- Return a Logical Vector with Missing Values removed in R Programming - complete.cases() Function
- Check whether a value is logical or not in R Programming - is.logical() Function
- Return an Object with the specified name in R Programming - get0() and mget() Function
- Search and Return an Object with the specified name in R Programming - get() Function
- Check if values in a vector are True or not in R Programming - all() and any() Function
- Return the Index of the First Minimum Value of a Numeric Vector in R Programming - which.min() Function
- Return the Index of the First Maximum Value of a Numeric Vector in R Programming - which.max() Function
- Get Indices of Specified Values of an Array in R Programming - arrayInd() Function
- Applying a Function over an Object in R Programming - sapply() Function
- Print the Value of an Object in R Programming - identity() Function
- Convert type of data object in R Programming - type.convert() Function
- Create an Object of mode call in R Programming - call() Function
- Calculate Cumulative Product of a Numeric Object in R Programming – cumprod() Function
- Check if Object is of the Character Data type in R Programming - is.character() Function
- Get the number of columns of an Object in R Programming - ncol() Function
- Checking if the Object is a Factor in R Programming - is.factor() Function

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.