Open In App

How to find Nth smallest value in vector in R ?

In this article, we will discuss how to find the Nth smallest in vector in the R programming language.

Steps –

Syntax:



sort(vector name ) [n value])

Parameter:



  • Vector name is the vector which we created.
  • N value is which largest number you want to print.

Example 1:




a<- c(1,3,4)
  
x = readline();
x = as.integer(x);
  
print(sort(a)[x])

Output:

[1] 1

Example 2:




a<- c(3453,39898,-997784)
  
x = readline();
x = as.integer(x);
  
print(sort(a)[x])

Output:

[1] 39898

Article Tags :