
Last chance! 50% off unlimited learning
Sale ends in
Intended for use in i
in [.data.table
, i.e., for subsetting/filtering.
Syntax should be familiar to SQL users, with interpretation as regex.
like(vector, pattern, ignore.case = FALSE, fixed = FALSE)
vector %like% pattern
vector %ilike% pattern
vector %flike% pattern
Logical vector, TRUE
for items that match pattern
.
Either a character
or a factor
vector.
Pattern to be matched
logical
; is pattern
case-sensitive?
logical
; should pattern
be interpreted as a literal string (i.e., ignoring regular expressions)?
Internally, like
is essentially a wrapper around base::grepl
, except that it is smarter about handling factor
input (base::grep
uses slow as.character
conversion).
DT = data.table(Name=c("Mary","George","Martha"), Salary=c(2,3,4))
DT[Name %like% "^Mar"]
DT[Name %ilike% "mar"]
DT[Name %flike% "Mar"]
Run the code above in your browser using DataLab