R Language Searching and Sorting

I wrote an article titled “R Language Searching and Sorting” in the September 2016 issue of Visual Studio Magazine. See https://visualstudiomagazine.com/articles/2016/09/01/r-language-searching-and-sorting.aspx.


In a nutshell, R has a built-in sort function that can sort the values in a vector using a shell sort, a radix sort and a quicksort. You can also write program-defined sorting functions using R language primitives.

R has a large number of built-in sequential search functions. The most commonly used are the match, is.element and which.max functions, plus the %in% operator, but none of these allow you to control the epsilon for floating point value equality. You can write a program-defined sequential search function with an epsilon tolerance when needed. R doesn’t have a built-in binary search function, but writing such a function isn’t too difficult.

I use several programming languages and don’t have too much difficulty switching from one to another. But because R is so different from most languages, it takes me a bit longer to switch to R when I’m using another language. For example, to search an array in most languages you’d use a function named something like IndexOf, but in R you have many choices, none of which work like IndexOf.

This entry was posted in R Language. Bookmark the permalink.