In: Computer Science
Write the code to return the output in Rstudio. What is the code?
Code: x <- c(28, 69, 5, 88, 19, 20)
Output must be:
[1] 4 2 1 6 5 3
The following is the R code for above question.
x <- c(28, 69, 5, 88, 19, 20) #initialize the 1d vector x
sort(x,decreasing=TRUE,index.return=TRUE)$ix #sort the vector in descending order and use index.return as TRUE. This will return you the indexes original numbers after modified. Also use $ix to print only indexes. Else, it will return a list with sorted values and $ix as indexes.
I will also attach the output and code screenshot for your reference.
Output and code Screenshot:
#Please dont forget to upvote if you find the solution helpful. Feel free to ask doubts if any, in the comments section. Thank you