Optimisation: sort or order and indicating default parameter
First, it is better to use sort(x) or x[order(x)]: > x <- sample(1:100, 100) > system.time({ + for (i in 1:100000) y <- x[order(x, decreasing = FALSE)] + }) utilisateur système écoulé 1.908 0.043 1.965 > system.time({ + for (i in 1:100000) y <- sort(x, decreasing = FALSE) + }) utilisateur système écoulé 2.993 0.035 3.043 Clearly the syntax x[order(x)] is more rapid (1/3 more fast). Now a second test: decreasing = FALSE is the default; what is the difference if it is not indicated: > system.time({ + for (i in 1:100000) y <- x[order(x)] + }) utilisateur système écoulé 1.907 0.037 1.952 > > system.time({ + for (i in 1:1000...