current position:Home>R language returns the position of data in the sorted array

R language returns the position of data in the sorted array

2022-02-04 17:26:00 CSDN Q & A

R Language requires you to write a function , Returns the position of the original data in the sorted array




Take the answer :

The code can be written like this :

pos<-function(x){    z=c()    y=sort(x)    for (i in 1:length(y))    for (j in 1:length(x))    if (y[i]==x[j])    z=c(z,j)    return(z)}arr=array(c(2,8,6,4))print(pos(arr))
r$> source('r28.r')[1] 1 4 3 2

If help , Please accept . Click on the top right corner of my answer 【 Adopt 】 Button .


copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/02/202202041725583583.html

Random recommended