Ad space (banner)
๐Ÿ“ŠR Lessons
Lesson 22 / 68

Searching a vector (%in%)

This lesson covers searching a vector with R's %in% operator, with the aim of checking whether a value is present.

value %in% vector tells you whether the value is in the vector. It is a distinctive R notation that looks like an operator.

The sample code checks whether "orange" is in the vector with "orange" %in% fruits. The unusual percent-wrapped form is a piece of R notation rarely seen elsewhere.

A common early stumble is simply getting used to writing %in%. The percent signs feel odd at first but read intuitively once they are familiar.

In professional work, %in% comes up constantly for checking whether a data frame column contains particular values.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run R directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)