#' general_info_all_participants function
#' @param dataset original dataset containing all info about participants
#' @return dataframe with five columns:
#' PIN, version, location, duration of the game and
#' number of actions (key presses and mouse clicks performed)
#' @importFrom dplyr %>% count select group_by filter mutate row_number n lag
#' @export
#' @examples
#' general_info_all_participants(dataset)
general_info_all_participants <- function(dataset){
if (nrow(dataset) == 0 || ncol(dataset) == 0){
stop("Columns or/and rows are empty")
}
tab1 <- dataset %>%
select(PIN, version, timestamp, location) %>%
group_by(PIN) %>%
filter(row_number()==1 | row_number()==n()) %>%
mutate(time_spent = timestamp - lag(timestamp)) %>%
filter(!is.na(time_spent)) %>%
select(-timestamp)
tab2 <- dataset %>%
select(PIN, event.type) %>%
filter(event.type == 'key press') %>%
group_by(PIN) %>%
count()
fin <- data.frame(merge(tab1, tab2, by='PIN'))
names(fin) <- c("PIN", "version", "location","total_time", "num_acts")
return(fin)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.