1

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?

James Z
  • 12,209
  • 10
  • 24
  • 44
Neku
  • 23
  • 3
  • Please consider to review your question according to SO guidelines https://stackoverflow.com/help/how-to-ask, and whether possible, share an extract of your data. Which is the format you're looking for? a string with 12 zeros followed by 8 numbers or what? – Scipione Sarlo Jan 05 '18 at 17:51
  • 2
    I don't understand the pattern you want, is it 14 zeros followed by 6 digits? Also, your `if` statements do not make sense. – Rui Barradas Jan 05 '18 at 17:51

0 Answers0