0

This seems likely to have a simple solution but I am having a hard time getting it. How do I convert this string to numeric?

> a <- "1:10"

Desired solution should be

> 1:10
[1]  1  2  3  4  5  6  7  8  9 10

I have tried as.numeric() (doesn't work), strsplit ":" and getting the end points 1 and 10 (can work but seems clumsy) but is there some simpler way? Thanks.

statsgrad1990
  • 89
  • 1
  • 3

1 Answers1

2

You can use eval() and parse()

eval(parse(text ="1:10"))
Damiano Fantini
  • 1,925
  • 9
  • 11