1

I have a column in R which looks like below:

won <- c("\001", rep("\\0",3), "\001")

 won
\001
 \\0
 \\0
 \\0
 \\0
\001

There are two possible values, \0 or \001

I am wondering what the most efficient route is to change these values to 0 (for \0) and 1 (for \001). I'm sure gsub() is one option, it's jut not clear if it's the way to go to alter two separate string values.

David LeBauer
  • 31,011
  • 31
  • 115
  • 189
ATMathew
  • 12,566
  • 26
  • 69
  • 76

1 Answers1

1

For this specific case:

2 - nchar(won)

Here is another option:

ifelse(won == "\001", 1, 0)
David LeBauer
  • 31,011
  • 31
  • 115
  • 189