Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Munge mapt obs from tape format to data table.
library(readr)
library(dplyr)
library(tibble)
# Input CSV
input_path <- '/tmp/dahee_coding.csv'
input_df <- read_csv(input_path)
# Veena's observations are row 1
row_1 <- as.list(input_df[1,])
names(row_1) <- NULL
veena_obs <- row_1[3:length(row_1)]
# Dahee's observations are row 2
row_2 <- as.list(input_df[2,])
names(row_2) <- NULL
dahee_obs <- row_2[3:length(row_2)]
# Convert from tape format to table format
# Events have 4 observations
observations_to_dataframe <- function(obs){
list_of_cols <- split(obs, f = seq(1,4))
list_of_values <- sapply(list_of_cols, as.vector)
df <- as.data.frame(list_of_values)
names(df) <- c('measure', 'ascribee', 'performance', 'time')
df %>% mutate_all(unlist)
}
veena_df <- observations_to_dataframe(veena_obs)
veena_df_annoated <- veena_df %>%
mutate(observer="veena", evt=paste0('evt', row_number())) %>%
select(observer, evt, measure, ascribee, performance, time)
dahee_df <- observations_to_dataframe(dahee_obs)
dahee_df_annotated <- dahee_df %>%
mutate(observer="dahee", evt=paste0('evt', row_number())) %>%
select(observer, evt, measure, ascribee, performance, time)
combined_obs_annoated <- rbind(veena_df_annoated, dahee_df_annotated)
# Write munged data to disk
out_path <- '/tmp/mapt_coding.csv'
write_csv(combined_obs_annoated, out_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.