R/physio-summary_eda.R

Defines functions summary_eda.physio

Documented in summary_eda.physio

#' summary_eda.physio()
#'
#' Calculates the average eda values per event. Arrousels per Event can be identified. Time information is kept as well. 
#'
#' @param data; a dataframe generated by match_marker_eda.physio
#' @return dataframe
#' @export

summary_eda.physio <- function(data) {
  store <- NULL
  sum_eda <- data$AverageEda[1]
  count <- 1
  event <- data$EVENT[1]
  time <- data$Time[1]
  index <- 1:(nrow(data) - 1)
  for (i in index){
    if (data$EVENT[i] == data$EVENT[i+1]){
      sum_eda <- sum_eda + data$AverageEda[i+1]
      count <- count + 1
    } else {
      store <- c(store, sum_eda/count)
      event <- c(event, data$EVENT[i+1])
      time <- c(time, data$Time[i+1])
      sum_eda <- data$AverageEda[i+1]
      count <- 1
    }
  }
  store <- c(store, sum_eda/count)
  data.frame(Time = time, Event = event, AverageEda = round(store, 2))
}
Fiddleman/NeuroIS documentation built on Nov. 1, 2017, 7:03 a.m.