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
A single line sed command can remove quotes from start and end of the string. The above sed command execute two expressions against the variable value. The first expression 's/^"//' will remove the starting quote from the string. Second expression 's/"$//' will remove the ending quote from the string.
Just use "\"" or '"' to match a single double quote.
To remove double quotes just from the beginning and end of the String, we can use a more specific regular expression: String result = input. replaceAll("^\"|\"$", ""); After executing this example, occurrences of double quotes at the beginning or at end of the String will be replaced by empty strings.
Just try noquote(a)
noquote("a")
[1] a
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With