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

I am new here with quite limited English knowledge. I will try to get my question easily understood.

I am doing an eye tracking experiment trying to detect the fixation distribution on two areas (Areas of interest, AOIs named "agent" and "patient") along the time. I have divided the whole time into time bins. And got the following list for example:
37%201

To finish the analysis, I need to split the span.bin into separate bins, like the following:

48

That means each row is a bin. Is it possible to solve the problem with R?

Any suggestions or ideas would be of great help!! Thanks!

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

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.