Search code examples
rquotes

Remove quotes from a character vector in R


Suppose you have a character vector:

char <- c("one", "two", "three")

When you make reference to an index value, you get the following:

> char[1]
[1] "one"

How can you strip off the quote marks from the return value to get the following?

[1] one

Solution

  • as.name(char[1]) will work, although I'm not sure why you'd ever really want to do this -- the quotes won't get carried over in a paste for example:

    > paste("I am counting to", char[1], char[2], char[3])
    [1] "I am counting to one two three"