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 –
- Create vector
- Take input from the user using the function readline().
- Convert data from string to int using the function as.integer().
- In this step, we are finding nth largest number using
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:
R
a<- c (1,3,4) x = readline (); x = as.integer (x); print ( sort (a)[x]) |
Output:
[1] 1
Example 2:
R
a<- c (3453,39898,-997784) x = readline (); x = as.integer (x); print ( sort (a)[x]) |
Output:
[1] 39898
Please Login to comment...