Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (5.3k 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

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

Browse Categories

...