Sort Descending All Data.frame Columns

I am doing this now, but I cannot find a reasonable solution.

I would like to sort all columns of data.frame in descending order.

Example data, for example:

CustomData <- data.frame(Value1=rnorm(100,1,2), Value2=rnorm(100,2,3), Value3=rexp(100,5), Value4=rexp(100,2)) 

Works for a single column:

 CustomData[order(CustomData$Value1, decreasing=FALSE), ] 

How to sort all column data in descending / increasing order in a reasonable way? thanks.

I also tried something like this, as posted elsewhere, but does not work as indicated.

 CustomData[do.call(order, as.list(CustomData)),] 
+6
source share
2 answers
 CD.sorted <- apply(CustomData,2,sort,decreasing=F) 
+12
source

Using do.call is much faster.

Ascending.

 CustomData[do.call(order, CustomData),] 

To reduce the order, the syntax is a little more complicated, because we must pass the argument "decreasing".

 CustomData[do.call(order, c(CustomData, list(decreasing=TRUE))),] 
0
source

Source: https://habr.com/ru/post/1498051/


All Articles