I have xboth
x
x <- c("7", "2", "3", "8", "8")
I need a conclusion
[1] "2" "3" "8"
and delete one of 8 and 7. Therefore, delete one of the largest two numbers.
There are many ways to achieve this. I think that the vector x should be dropped to numeric, but this works.
x <- (c('7','2','3','8','8')) # read in data remove <- tail(unique(x[order(x)]),2) # take the unique elements and sort, identifying the last 2 x[ - c(which(x==remove[1])[1], which(x==remove[2])[1]) ] #remove only the one of each of the two found
Here is the opportunity with match().
match()
x[-match(tail(sort(unique(x)), 2), x)] # [1] "2" "3" "8"
Another option using which.max
which.max
x[-c(which.max(x), match(max(x[x != max(x)]), x))] #[1] 2 3 8
Source: https://habr.com/ru/post/1616002/More articles:org.hibernate.MappingException: Unknown object: pack1.Persoana - hibernateFind the indices of those elements that will be equal to x after adding their values - javascriptИспользуя UWP и Raspberry Pi, как я могу измерить частоту входного сигнала, который колеблется порядка 1000 Гц (1 миллисекунда)? - c#How to relate the reaction state to the observed RxJS flow? - javascriptwoocommerce applies coupon software bug - phpC # EPPLUS cannot get cell value - c #In the context, why can't I cancel the list by skipping the last item in the same bracket? - pythonYoutube Play / Pause Animated Vector Drawable on Android - androidParse different JSON responses without using POJO classes in Java - javaEcho user details after successful login - html5All Articles