1

I have the following object.

object1 <- "c(3:6, 8, 10:13, 16, 21)"

I'd like to convert object1, which is a character string, into the following numeric vector.

object2 <- c(3:6, 8, 10:13, 16, 21)

Are there any good solutions? base R solutions are preferred but I'm open to anything. Thanks!

David Moore
  • 670
  • 3
  • 15

1 Answers1

3

R base solution using eval+parse

> eval(parse(text=object1))
 [1]  3  4  5  6  8 10 11 12 13 16 21
Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138