I would like to get the sequence of numbers from the start and end positions of each row:
library(dplyr)
df <- data.frame(
start = c(1,5,7,9,10),
end = c(2,10,17,18,20)
)
#I tried
df <- df %>%
rowwise() %>%
mutate(
seq = list(seq(start, end))
)
#But I get the below Error
#Fehler in seq.default(start, end) : 'from' must be of length 1
#If I just add numbers it works fine
df <- df %>%
rowwise() %>%
mutate(
seq = list(seq(1,5))
)
#Output
start end seq
<dbl> <dbl> <list>
1 1 2 <int [5]>
2 5 10 <int [5]>
3 7 17 <int [5]>
4 9 18 <int [5]>
5 10 20 <int [5]>
How do I generate sequences using the start and end values for each row?