I want to subset a data table (DS
) based on a column (Col
) with the format "00000000000000123456"
using regular expressions in R.
Numbers that meet this format should be output to DS_Correct
and those that do not match should be output to DS_Error
.
I tried using the stringr functions:
DS_Correct <- if(str_match (DS$Col,"/^[1-9][:digits:]{0,12}$/)) > 0
DS_Error <- if(str_match (DS$Col,"/^[1-9][:digits:]{0,12}$/)) > 0
But i get the error:
Error: '\d' is an unrecognized escape in character string starting ""/^[1-9]\d"
What am i doing wrong?