Last active
March 29, 2018 16:06
-
-
Save sfirke/c26a90d13d43b2c4a4c5e5c3a8b372a5 to your computer and use it in GitHub Desktop.
(roughly) handle SurveyMonkey exports where the variable names are split over the first two rows
This file contains 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
# Fix dual-row names: if the first row is not NA or containing the word "response", use the one from the first row | |
# Note: read your SurveyMonkey .csv with readr::read_csv, not read.csv - otherwise this may not work | |
library(dplyr) | |
library(janitor) | |
fix_SM_dual_row_names <- function(dat){ | |
current_names <- names(dat) | |
row_1 <- unlist(dat[1, ]) | |
new_names <- ifelse(row_1 %in% c("Response", "Open-Ended Response", NA), | |
current_names, | |
row_1) | |
dat[-1, ] %>% | |
setNames(new_names) %>% | |
janitor::clean_names() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment