I'm doing a text mining project where I have to manually enter a double quote as an element inside a vector. I tried char[10]='"'#where i enclosed the double quote in a pair of single quotes. But the result is [1] "\"". Somehow a back slash is added automatically. I also tried to enclose the double quote in a pair of double quotes. That didn't work either. I'm using Mac and latest release of R. Thank you! Bonnie Yuan -- View this message in context: http://r.789695.n4.nabble.com/how-to-manually-enter-an-double-quote-as-data-feed-tp4192283p4192283.html Sent from the R help mailing list archive at Nabble.com.
how to manually enter an double quote as data feed?
3 messages · bonnieyuan, Justin Haynes, Nordlund, Dan (DSHS/RDA)
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111213/3a0030fe/attachment.pl>
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of bonnieyuan Sent: Tuesday, December 13, 2011 2:04 PM To: r-help at r-project.org Subject: [R] how to manually enter an double quote as data feed? I'm doing a text mining project where I have to manually enter a double quote as an element inside a vector. I tried char[10]='"'#where i enclosed the double quote in a pair of single quotes. But the result is [1] "\"". Somehow a back slash is added automatically. I also tried to enclose the double quote in a pair of double quotes. That didn't work either. I'm using Mac and latest release of R. Thank you! Bonnie Yuan
Bonnie,
The backslach character in not actually there. Since the double quote character has special meaning in R, it needs to be 'escaped' to change its special meaning to become a literal double quote character. That is the function of the \ escape character.
Try the following
s1 <- '"' #assign as you did
s2 <- "\"" #assign using escape character
s1 #displays with backslash
nchar(s1) #but there is only 1 character in the string
s2
nchar(s2)
print(s1) #prints backslash indicating literal double quote
cat(s1,'\n') #cat function displays without the backslash
#notice n character is escaped, creating a newline character
Hope this is helpful,
Dan
Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204