Remove quotes from a character vector in R

前端 未结 10 2155
盖世英雄少女心
盖世英雄少女心 2020-11-29 01:06

Suppose you have a character vector:

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

When you make reference to an index value, you get the follo

相关标签:
10条回答
  • 2020-11-29 01:40

    Here is one combining noquote and paste:

    noquote(paste("Argument is of length zero",sQuote("!"),"and",dQuote("double")))
    
    
    #[1] Argument is of length zero ‘!’ and “double”
    
    0 讨论(0)
  • 2020-11-29 01:48

    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"
    
    0 讨论(0)
  • 2020-11-29 01:50

    I'm just guessing, is this in the ball park of what you're trying to achieve?

    > a <- "a"
    > a
    [1] "a" # quote yes
    > as.factor(a)
    [1] a #quote no
    
    0 讨论(0)
  • 2020-11-29 01:51

    Just try noquote(a)

    noquote("a")

    [1] a

    0 讨论(0)
提交回复
热议问题