Elemental selection sort functions in R
Here are some ideas, somewhat sorted by order of importance. I hope it helps.

1) There is a problem with your second function, see that

&gt; selsr(1:5)
[1] 2 3 4 5 1


You should be doing

j &lt;- i - 1L + which.min(x[i:n])


2) Your choice of 1:(n - 1) will not properly handle the n == 0. Also, it does handle the n == 1 case properly but it is a bit of luck considering you are looping over 1:0... The robust alternative to the : operator is to use seq_len or seq_along. Or you could just have a if (n &lt; 2L) return(x) near the top of your functions.

3) While on the topic of corner cases, your code assumes that x is a numerical vector. You could be checking for that by adding:

stopifnot(is.vector(x), is.numeric(x))


4) You can achieve the swaping without a temporary variable by doing:

x[c(i, j)] &lt;- x[c(j, i)]


5) min is a questionable variable name, given it is also the name of a base function.

6) This is debatable: I would get rid of the if (j != i) condition since it won't hurt doing the swap even if j == i. IMO, the simpler code is preferable to the marginal computation time gain.

7) A nit: know the difference between 1 (numeric) and 1L (integer). Here you are using 1 when you mean to use 1L, which causes unnecessary conversions from integer to numeric (though the : operator brings you back to integers by doing the opposite conversion).