Problem: How to insert increment sequence of numbers by 30 between two numbers for each unique Patient ID.
I have 1000+ patient id in real data sets. Tidyverse solution would be awesome help.
Thank you
Sample data
library (tidyverse)
sample_data <- tibble::tribble(
~Patient_ID, ~min, ~max,
"ID_1", -90, 270,
"ID_2", -60, 180)
I am expecting to have a sequence of numbers incremental by 30 for each patient ID.
Expected output
expected_output <- tibble::tribble(
~Patient_ID, ~Numbers,
"ID_1", -90,
"ID_1", -60,
"ID_1", -30,
"ID_1", 0,
"ID_1", 30,
"ID_1", 60,
"ID_1", 90,
"ID_1", 120,
"ID_1", 150,
"ID_1", 180,
"ID_1", 210,
"ID_1", 240,
"ID_1", 270,
"ID_2", -60,
"ID_2", -30,
"ID_2", 0,
"ID_2", 30,
"ID_2", 60,
"ID_2", 90,
"ID_2", 120,
"ID_2", 150,
"ID_2", 180
)
My attempt which doesn't work
sample_data %>%
group_by(Patient_ID) %>%
mutate(Seq = seq(min, max, by = 30))