Last active
May 12, 2016 22:51
-
-
Save aaroncharlton/8e0818b6fa409cd2244d to your computer and use it in GitHub Desktop.
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
# 1. You will need to do a one-time install of the dplyr package (code on next line). | |
# install.packages("dplyr") | |
# 2. make sure to name the student ID column "ID" in both files | |
# 3. files must have two header rows (qualtrics-style) and be in .csv format | |
# 4. update all three of the following variables and don't forget the quotes! | |
qualtrics_file <- "Authenticity2.csv" | |
demos_file <- "Spring 2015 Demos %28UPPER 3-8%29 (1).csv" | |
save_location <- "C:/Users/abc/Downloads" | |
### shouldn't need to modify below this line #### | |
# bring in study data | |
library(dplyr) | |
setwd(save_location) | |
qualtrics <- read.csv(qualtrics_file, stringsAsFactors=FALSE)[-1,] %>% | |
.[grepl("^95", .$ID), ] # remove responses without a student ID, ie, "test" | |
# bring in demographic data | |
demos0 <- read.csv(demos_file, skip=2, head=FALSE, stringsAsFactors=FALSE) | |
demos1 <- read.csv(demos_file) | |
names(demos0) <- names(demos1) | |
demos0$ID <- as.character(demos0$ID) | |
distinctdemos <- distinct(demos0,ID) # discard duplicate demos | |
# merge data | |
library(dplyr) | |
alldata <- NULL | |
alldata <- left_join(qualtrics,distinctdemos, by="ID") | |
new_file <- paste("merged-data",Sys.Date(),".csv") | |
write.table(alldata, file=new_file, sep=",", na=" ", col.names=NA) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment