0 votes
1 view
in R Programming by (5k points)

a <- c(1, 2, 0, 3, 7)

I am looking for a function to return the index of the smallest value, 3. What is it?

1 Answer

0 votes
by (23.2k points)

To return the index of the smallest value in a vector, you can use the which.min() function from the base package as follows

v=c(100,300,150,400,50,450,250,150,400)

 which.min(v)

[1] 5

You can also use the which function from base R as follows:

which(v == min(v))

[1] 5

...