0

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

1
  • Your question heading and question looks different. You have one extra `\` in the question heading. Jun 19, 2015 at 7:45

1 Answer 1

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.

5
  • I didn't understand! May you elaborate! Jun 19, 2015 at 7:42
  • So to match a pattern "-mean() or std()" we add "\(\)" in grep. right? Jun 19, 2015 at 7:46
  • @RishabhVerma i have added explaination. Hope it helps. If you need more do tell. Jun 19, 2015 at 7:46
  • @RishabhVerma Yes to match "-match()" or "-std()" you need to add "()" Jun 19, 2015 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. Jun 19, 2015 at 7:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .