Character and character and strings in R

Hi,
I have a question about character vectors in R, let's consider this:

text1 <- read.text('summary.txt') 
text2 <- c("time", "watch")

In my summary.txt there are words inside:

"start", "end", "duration", "id", "latitude", "longitude", "duration", "green", "pink", "blue"

When I want to see both of them in the console that gives me:

text1
[1] "\"start\", \"end\", \"duration\", \"id\", \"latitude\", \"longitude\", \"duration\", \"green\", \"pink\", \"blue\""

text2
[1] "time"  "watch"

How to convert txt1 to look normal, like txt2 ? Why does text1 consist of backslashes and quotation marks ?

class(text1)
[1] "character"

class(text2)
[1] "character"

Any thoughts will be greatly appreciated, thank you.

In text1, the double quotes are part of the actual text. When you print text1, the outer double quotes indicate that characters are being displayed and the back slashes indicate that the following double quotes are in the text. In text2, the double quotes indicate that characters are being displayed. I can mimic text1 and then remove the double quotes like this:

text3 <- c('"first"', '"second"')
> text3
[1] "\"first\""  "\"second\""
> text4 <- gsub(pattern = '"', replacement = '', text3)
> text4
[1] "first"  "second"

Thank you very much @FJCC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.