0

I think this will be an easy question, but i could not find the answer until now. I have a dataframe with a start of a position and an end of a position like this:

name <- c("pr1", "pr1", "pr3")
start <- c(1,7,10)
end <- c(5,8,15)
ds <- cbind(name,start,end)
g <- as.data.frame(ds)
print(g)

Now, i want to have all positions from start to the end into a new data frame with each position named by the according name. Like this:

name  position
pr1   1
pr1   2
pr1   3
pr1   4
pr1   5
pr2   7
pr2   8
pr3   10
pr3   11
...  ... 

Does anyone know how to solve this? Sorry if this has been asked before, I am new here :`D

Thanks alot!

EDIT: Answer can be found here: Expand ranges defined by "from" and "to" columns

CoDa
  • 132
  • 10
  • 1
    Using `tidyverse` : `g %>% mutate(position = map2(start, end, seq)) %>%unnest(position) %>% select(name, position)` – Ronak Shah Feb 22 '21 at 10:27
  • thanks alot, i found another answere here: https://stackoverflow.com/questions/11494511/expand-ranges-defined-by-from-and-to-columns – CoDa Mar 04 '21 at 10:07

0 Answers0