Reordering and sorting elements of a vector

set.seed(231)
x <- rnorm(n=10)
x
 [1] -0.53310192 -2.31166378 -0.95419786  0.26251575 -0.47335746  0.21739728
 [7]  0.06292205 -0.87782986  0.56368979 -0.03432728
x.srt <- sort(x)
x.srt
 [1] -2.31166378 -0.95419786 -0.87782986 -0.53310192 -0.47335746 -0.03432728
 [7]  0.06292205  0.21739728  0.26251575  0.56368979
sort(x,decreasing=TRUE)
 [1]  0.56368979  0.26251575  0.21739728  0.06292205 -0.03432728 -0.47335746
 [7] -0.53310192 -0.87782986 -0.95419786 -2.31166378
stex <- c("1","11","A","a","Ab","AB","ab","aB","B","b","bb")
sort(stex)
 [1] "1"  "11" "a"  "A"  "ab" "aB" "Ab" "AB" "b"  "B"  "bb"
set.seed(2134)
x <- rnorm(6)
x
[1]  0.6549052 -0.2099869 -0.6148580 -0.2740271 -0.7234317  1.4371483
y <- rnorm(6)
y
[1] -0.09385485 -0.05070594  0.77188553  0.36295090  1.12152639  0.72011916
ii <- order(x)
x.ordered <- x[ii]
y.ordered <- y[ii]
x.ordered
[1] -0.7234317 -0.6148580 -0.2740271 -0.2099869  0.6549052  1.4371483
y.ordered
[1]  1.12152639  0.77188553  0.36295090 -0.05070594 -0.09385485  0.72011916
jj <- order(ii)
all(x.ordered[jj] == x)
[1] TRUE
all(y.ordered[jj] == y)
[1] TRUE

Downloadable R script and interactive version

Explanation

The link with the “jupyterhub” icon directs you to an interactive Jupyter1 notebook, which runs inside a Docker container2. There are two variants of the interative notebook. One shuts down after 60 seconds and does not require a sign it. The other requires sign in using your ORCID3 credentials, yet shuts down only after 24 hours. (There is no guarantee that such a container persists that long, it may be shut down earlier for maintenance purposes.) After shutdown all data within the container will be reset, i.e. all files created by the user will be deleted.4

Above you see a rendered version of the Jupyter notebook.5

1

For more information about Jupyter see http://jupyter.org. The Jupyter notebooks make use of the RKernel package.

2

For more information about Docker see https://docs.docker.com/. The container images are run with docker spawner.

3

ORCID is a free service for the authentication of researchers. It also allows to showcase publications and contributions to the academic community such as peer review.. See https://info.orcid.org/what-is-orcid/ for more information.

4

The Jupyter notebooks come with NO WARRANTY whatsoever. They are provided for educational and illustrative purposes only. Do not use them for production work.

5

The notebook is rendered with the help of the nbsphinx extension.