0

I have a large df that I am trying to clean up, it goes something like this

 Name1. Name2. Var1. Var2....
 name?    ...   ...   ...
 name?    ...   ...   ...

So the Names are encrypted and they do include special characters that I do NOT want to remove.

I have been using gsub(), but it does not remove the '?': I just want to remove the single '?' at the end of the names that Excel somehow added on.

MyData$Name1 <- gsub("?", "", MyData$Name1)

Nothing seem to have changed and I do not get any error codes.

    Name1. Name2. Var1. Var2....
    name?    x     a     1 ...
    name?    y     b     2 ...

Does anyone have any prior experience with something like this?

Viss
  • 47
  • 9

1 Answers1

3

? is a metacharacter, and has a special meaning in regular expressions. In order to get a literal question mark, you must escape it. Use:

gsub("\\?", "", MyData$Name1)
G5W
  • 36,531
  • 10
  • 47
  • 80
  • 1
    `?` also has a syntax purpose in lookarounds, and maybe somewhere else I can't think of right now. – Tim Biegeleisen Jun 05 '18 at 01:49
  • 1
    True. Also used to make parentheses _NOT_ a capture group. I guess the real point is that it has special meaning within regular expressions. – G5W Jun 05 '18 at 01:54