0

I've been given a datafile where one of the fields (columns) is called code_id. Some of the codes in this field include "22K..", "22K4.", and "22K7.". Now I'm trying to subset a data.table to pull out the rows containing explicit values 22K.., and no others. My first attempt, treats the "." as a wildcard for any character and thus I get all three. I've tried several permutations of "escaping" the . using single or double \ characters, both with and outwith quotation marks but nothing seems to work. I guess I'm trying to stop R treating . as a wildcard and get it to treat it as a literal ".". What basic syntax am am I missing. The code attempted is :

K22Kcodes <- ClinicalTable[code_id == "22K.."]

Thx. J

Jim Maas
  • 1,481
  • 2
  • 16
  • 36
  • 4
    There are no wildcards with `==`... please provide a reproducible example. – s_baldur Jun 24 '21 at 13:58
  • 1
    If you want to use regex, use the `%like%` or `%ilike%` operator instead of `==` with data.table. Or simply `grep()`. – andschar Jun 24 '21 at 14:04
  • Thx. I produced a MWE and it worked correctly, went back to my original and it also worked correctly! Not sure what I've done or how I've fixed it! – Jim Maas Jun 24 '21 at 14:16

0 Answers0