I have a data frame where one column contains a range (or ranges) of numbers. I would like to turn this into a list of numbers based of the given range.
Example input:
"35-40"
or
"35-43, 45-47"
This should yield:
[1] 35 36 37 38 39 40
and
[1] 35 36 37 38 39 40 41 42 43 45 46 47
we use substr to extract parts of string to get beginning and end of numeric list. we use as.numeric to convert strings extracted to numbers. we use the colon to create the list of numbers . it will also work for multiple parts of list
You can use
eval(parse(...))
as follows,or
EDIT
Based on your latest edit, then,
We can do a split and with
Map
, get the numbersIf we need to find the sequence within the string
Update
If we have multiple elements in a string
data