Skip to content

Instantly share code, notes, and snippets.

@briandk
Created July 29, 2011 20:29
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 briandk/1114667 to your computer and use it in GitHub Desktop.
Save briandk/1114667 to your computer and use it in GitHub Desktop.
Stitching together multiple CSV files in R
TidyMultipleChoiceData <- function(file) {
multiple.choice.columns <- c("name",
"mc1",
"mc2",
"mc3",
"mc4",
"mc5",
"mc6",
"mc7",
"mc8"
)
dd <- read.csv(file, header = TRUE) # Load the files
dd <- subset(dd, select = multiple.choice.columns) #Select multiple choice columns
dd <- transform(dd, instructor = ExtractInstructorFromFilename(file)) # append a column to indicate source instructor
return(dd)
}
ExtractInstructorFromFilename <- function(filename) {
return(gsub(".*/([a-z,A-Z]+).csv$", filename, replacement = "\\1", perl = T))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment