How to transform span bin information into separate bins in r?

Hi, welcome!

I can't give you a specifyc solution since you are not providing a REPRoducible EXample (reprex) but you can do something like this.

library(dplyr)
library(tidyr)
# Made up sample data
df <- data.frame(AOI_name = c("patient", "agent"),
                 Start_Bin = c(2, 10),
                 End_Bin = c(6, 14))

df %>% 
    gather(x, Bin, ends_with("Bin")) %>% 
    select(-x) %>% 
    group_by(AOI_name) %>% 
    complete(Bin = full_seq(Bin, period = 1))
#> # A tibble: 10 x 2
#> # Groups:   AOI_name [2]
#>    AOI_name   Bin
#>    <fct>    <dbl>
#>  1 agent       10
#>  2 agent       11
#>  3 agent       12
#>  4 agent       13
#>  5 agent       14
#>  6 patient      2
#>  7 patient      3
#>  8 patient      4
#>  9 patient      5
#> 10 patient      6

Created on 2019-06-24 by the reprex package (v0.3.0)

2 Likes