0

I currently have characters like "361:372" or "c(325, 326, 327, 344, 345, 346, 347, 348)", and I'm trying to use these as indices.

In other words, Is there a way to convert a character "361:372" to a vector c(361:372), or from "c(325, 326)" to c(325, 326)? I intend to use them as indices in a data frame, such as df[c(325, 326),].

Thank you so much for your time

kaih
  • 1
  • 1
  • You can try: `eval(parse(text = "361:372"))` – Haboryme Oct 07 '16 at 12:47
  • Thank you so much! This totally solves the first problem. However I actually have the two formats mixed together, would there be a way to convert from "c(1, 2)" to c(1, 2) as well? I tried eval("c(1, 2)") but this would just return a character – kaih Oct 07 '16 at 12:56
  • `eval(parse(text = "c(1, 2)"))` will return the result of c(1,2), i.e 1 and 2. – Haboryme Oct 07 '16 at 13:02
  • Oh wow didn't realise. Thank you Haboryme, this really helped! – kaih Oct 07 '16 at 13:04

0 Answers0