use of read.delim() when there are backslashes in the data in R
I have a tab delimited text file where there are backslashes in the file as follows:
V1 V2
abc 123
456 \23
nyc &^#
Ho开发者_开发百科wever, when I use read.delim('foo.txt')
, it adds an extra backslash as follows:
> read.delim('foo.txt')
V1 V2
1 abc 123
2 456 \\23
3 nyc &^#
Is there a way to change a parameter so this behavior doesn't happen?
It doesn't add an extra backslash. It just looks like it. What's nchar(foo$V2)?
\\ is the code for a single backslash, because \n is the code for a new line and so on. So if you see \\n its two characters - a backslash and a letter 'n', but \n is one character - a newline.
Its an escape mechanism.
> Z[,1]
[1] "\\1"
> nchar(Z[,1])
[1] 2
Its like the same reason I have to type four backslashes to get two in this text box...
精彩评论