<u>Completed Question</u>
Outputs to be matched to the functions are:
- 1,2,3,4,5
- 1,5,3,2,4
- 1, 4, 3, 5, 2
- 2, 18, 27, 43, 96
Answer:
- sort(x): 2, 18, 27, 43, 96
- order(x): 1, 5, 3, 2, 4
- rank(x)
: 1, 4, 3, 5, 2
- none of these
: 1, 2, 3, 4, 5
Step-by-step explanation:
Given the vector x: x <- c(2, 43, 27, 96, 18)
<u>Sort</u>
In R, the sort(x) function is used to arrange the entries in ascending or descending order. By default, R will sort the vector in ascending order.
Therefore, the output that matches the sort function is:
sort(x): 2, 18, 27, 43, 96
<u>Rank</u>
The rank function returns a vector with the "rank" of each value.
x <- c(2, 43, 27, 96, 18)
- 2 has a rank of 1
- 43 has a rank of 4
- 27 has a rank of 3
- 96 has a rank of 5
- 18 has a rank of 2
Therefore, the output of rank(x) is: 1, 4, 3, 5, 2
<u>Order</u>
When the function is sorted, the order function gives the previous location of each of the element of the vector.
Using the sort(x) function, we obtain: 2, 18, 27, 43, 96
In the vector: x <- c(2, 43, 27, 96, 18)
- 2 was in the 1st position
- 18 was in the 5th position
- 27 was in the 3rd position
- 43 was in the 2nd position
- 96 was in the 4th position
Therefore, the output of order(x) is: 1, 5, 3, 2, 4