strsplit in R with metacharacter

Posted by user1429852 on Stack Overflow See other posts from Stack Overflow or by user1429852
Published on 2012-06-01T04:21:36Z Indexed on 2012/06/01 4:40 UTC
Read the original article Hit count: 201

Filed under:
|
|
|
|

I have received a large amount of data where the delimiter is a backslash (obviously a bad choice). I'm processing it in R for computation, and having a hard time finding how to split the string since the backslash is a metacharacter. For example, a string would look like this:

"1128\0019\XA5\E2R\366\00=15"

and I want to split it along the "\" character, but when I run the strsplit command:

strsplit(tempStr, "\") Error in strsplit(tempStr, "\") : invalid regular expression '\', reason 'Trailing backslash'

When I try to used the "fixed" option, it does not run because it is expecting something after the backslash:

strsplit(tempStr, "\", fixed = TRUE)

Unfortunately, I can't preprocess the data with another program because the data is generated daily. Please help and thanks!

© Stack Overflow or respective owner

Related posts about string

Related posts about r