To find the index of an element in an array in R, you can use the which()
function. The which()
function returns the indices of the elements that satisfy a certain condition. Specifically, you can use it to find the index of an element that is equal to a certain value.
Here's an example code snippet to find the index of an element in an array:
main.r137 chars9 lines
In this code snippet, the which()
function is used to find the index of the element 30 in the my_array
array. The result is stored in the index
variable, and then printed to the console.
The output of this code snippet is:
main.r6 chars2 lines
This means that the index of the element 30 in the my_array
array is 3.
gistlibby LogSnag