Skip to contents

Several events may occur in response to a experimental stimulus, this function will add a sub-index allowing for segregation by the i-th event to a n-th stimulus.

Usage

add_event_index(df)

Arguments

df

Data Frame or Tibble with the following columns:

  • amplitude

  • sweep

  • stimulus

Value

Data Frame or Tibble with event index numbers in column the event_index.

Details

The first event for a given stimulus will always start with an index value of 1. If multiple events occur, and iterative index is created. If no events occur, the index takes a NA value.

Examples

simple_tbl <- tibble::tibble(
  sweep = as.ordered(c(1, 1, 1, 1, 2, 2, 2, 2, 2)),
  time_ms = c(405, 408, NA, 445, seq(405, 445, 10)),
  amplitude = c(100, 100, NA, 100, 100, 100, 100, 100, 100),
  stimulus = ordered(c(1, 1, 2, "r", 1, 2, "o", "o", "r"), levels = c(1, 2, "o", "r"))
)
add_event_index(simple_tbl)
#> # A tibble: 9 × 5
#>   sweep time_ms amplitude stimulus event_index
#>   <ord>   <dbl>     <dbl> <ord>          <int>
#> 1 1         405       100 1                  1
#> 2 1         408       100 1                  2
#> 3 1          NA        NA 2                 NA
#> 4 1         445       100 r                  1
#> 5 2         405       100 1                  1
#> 6 2         415       100 2                  1
#> 7 2         425       100 o                  1
#> 8 2         435       100 o                  2
#> 9 2         445       100 r                  1