Skip to content

Instantly share code, notes, and snippets.

@hauselin
Last active May 12, 2016 01:44
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 hauselin/299fc906e3de49b73cb2 to your computer and use it in GitHub Desktop.
Save hauselin/299fc906e3de49b73cb2 to your computer and use it in GitHub Desktop.
R functions for Qualtrics
#function to read raw data from Qualtrics
cleanQualtrics <- function(csvFile, rowAsHeader, skipRows) {
#this function assumes that you have named your
#Qualtrics questions properly when setting up the survey;
#if questions are properly named, then the first row
#will be most informative and suitable for use as column names
#read.csv sets header = T by default; stringsAsFactor set to FALSE to ensure strings aren't converted to factors
QualtricsRaw <- read.csv(csvFile, header = F, stringsAsFactors = F)
#row 1 contains the strings that we'd like to use as column names; select row 1 and turn them into characters
colNames <- as.character(QualtricsRaw[rowAsHeader,])
dat <- read.csv(csvFile, header = F, stringsAsFactors = F,
col.names = colNames,
skip = skipRows)
return(dat) #returns the dataframe with proper column names
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment