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.

1 Answer 1

1

For this specific case:

2 - nchar(won)

Here is another option:

ifelse(won == "\001", 1, 0)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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