0

Need to know about the function of \(\) in grep("-(mean|std)\(\)", x[,2])

  • Your question heading and question looks different. You have one extra `\` in the question heading. – Rakholiya Jenish Jun 19 '15 at 7:45
3

This matches ( and ) literally.

() is used as capturing groups in Extended Regular Expressions (as used by r's grep() or the grep command with the -E option) or Perl Compatible Regular Expression which extend Extended Regular Expressions (as used by r's grep(..., perl=TRUE) or some grep commands with the -P option).

Hence to match () literally, \ is used.

  • I didn't understand! May you elaborate! – Rishabh Verma Jun 19 '15 at 7:42
  • So to match a pattern "-mean() or std()" we add "\(\)" in grep. right? – Rishabh Verma Jun 19 '15 at 7:46
  • @RishabhVerma i have added explaination. Hope it helps. If you need more do tell. – Rakholiya Jenish Jun 19 '15 at 7:46
  • @RishabhVerma Yes to match "-match()" or "-std()" you need to add "()" – Rakholiya Jenish Jun 19 '15 at 7:47
  • @RishabhVerma You can accept the answer if you think it is correct and you are satisfied. This helps other in reading answers. – Rakholiya Jenish Jun 19 '15 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.