Was not sure how to title this question so if there are better suggestions please edit
Let's say we have this dataframe:
Dataset
df <- data.frame(start = c(10, 20), end = c(15,33), label = c('ex1','ex2'))
Which looks like this:
start end label
1 10 15 ex1
2 20 33 ex2
What I want to get
I want to expand from start
--> end
, like so:
pos label
1 10 ex1
2 11 ex1
3 12 ex1
4 13 ex1
5 14 ex1
6 15 ex1
7 20 ex2
8 21 ex2
9 22 ex2
10 23 ex2
11 24 ex2
12 25 ex2
13 26 ex2
14 27 ex2
15 28 ex2
16 29 ex2
17 30 ex2
18 31 ex2
19 32 ex2
20 33 ex2
What I have now
f <- function(x) {data.frame(pos = x$start:x$end, label = x$label)}
df %>% rowwise() %>% do(f(.))
While my solution works, my original dataset is much larger and doubt if this is efficient. Moreover, I want to include more columns than label
so I want to retrain all columns and just spread out the start
and end