Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(roughly) handle SurveyMonkey exports where the variable names are split over the first two rows
# 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