R Language Sequential Search

There are four main ways to search a vector in R. You can use the built-in matches() or is.element() function, the built-in %in% operator, or write a user-defined function.


The screenshot of a demo program illustrates these four techniques. The matches() and is.element() functions are useful when you’re looking for multiple occurrences of a target, or are searching for multiple targets. The %in% operator returns a Boolean but doesn’t allow you to control how floating point values are compared for equality. Writing a user-defined function requires some effort but gives you complete control over how the search works.

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