Sorting elements of a R Vector
sort() function is used with the help of which we can sort the values in ascending or descending order.
R
# R program to sort elements of a Vector # Creation of Vector X<- c (8, 2, 7, 1, 11, 2) # Sort in ascending order A<- sort (X) cat ( 'ascending order' , A, '\n' ) # sort in descending order # by setting decreasing as TRUE B<- sort (X, decreasing = TRUE ) cat ( 'descending order' , B) |
Output:
ascending order 1 2 2 7 8 11
descending order 11 8 7 2 2 1
R Vectors
R Vectors are the same as the arrays in R language which are used to hold multiple data values of the same type. One major key point is that in R Programming Language the indexing of the vector will start from ‘1’ and not from ‘0’. We can create numeric vectors and character vectors as well.
Contact Us