How can I convert the string:
a <- "c(\"4\", \"5\", \"7\", \"8\", \"9\", \"10\")"
to a vector of values: 4,5,7,8,9,10 ?
How can I convert the string:
a <- "c(\"4\", \"5\", \"7\", \"8\", \"9\", \"10\")"
to a vector of values: 4,5,7,8,9,10 ?
The not-so-likeable eval
parse
can be handy here
as.integer(eval(parse(text = a)))
#[1] 4 5 7 8 9 10
Or maybe you want to keep them as characters as your title indicates.
eval(parse(text = a))
#[1] "4" "5" "7" "8" "9" "10"
Based on how complicated the string is you could also extract all the digits from the string.
stringr::str_extract_all(a, "\\d+")[[1]]
Or in base R
regmatches(a, gregexpr("\\d+", a))[[1]]