R/count_event.R

Defines functions count_event

Documented in count_event

#' count_event  Count the event number for every AE at spefified timepoint
#'
#' @description  Count the event number for every AE at spefified timepoint
#'
#' @param total data set with ae data and patient data merged
#' @param day The study day of interest
#'
#' @keywords internal


count_event <- function(total = tot, day = 1){
  day_start <- ae <- treat <- tot <- day_end <- flag <- NULL

  tmp <- total %>%
    tidyr::drop_na() %>%
    dplyr::rowwise() %>%
    dplyr::mutate(flag = any(dplyr::between(day, day_start, day_end))) %>%
    dplyr::ungroup()

  tmp2 <- tmp %>%
    dplyr::group_by(ae, treat, .drop = FALSE) %>%
    dplyr::filter(flag == TRUE) %>%
    dplyr::summarise(n = n())
  tmp2$treat <- as.character(tmp2$treat)

  tmp2$treat <- as.factor(tmp2$treat)
  return(tmp2)
}

Try the adepro package in your browser

Any scripts or data that you put into this service are public.

adepro documentation built on July 6, 2021, 5:08 p.m.