Created
July 30, 2018 14:23
-
-
Save grosscol/a5f6cb494e31bb4e888f5bad04fa6b2c to your computer and use it in GitHub Desktop.
Munge mapt obs from tape format to data table.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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