Skip to content

Instantly share code, notes, and snippets.

@sfirke
Last active March 29, 2018 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfirke/c26a90d13d43b2c4a4c5e5c3a8b372a5 to your computer and use it in GitHub Desktop.
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
# 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