#Change to your own directory (where you keep the data file) dir = 'C:\\Users\\yoav\\Documents\\bigfiles\\qualtrics.iat\\gal.elinor\\raw' # Copied from Elad Zlotnick (from here: https://github.com/eladzlot/minnojs-qiat/blob/master/qiat.R) # Parse csv generated by minnoJS # # @param df a data frame # @param id the column name holding the ids # @param data the column name holding the data (we assume the data holds an array of unnested objects) # # @example # qiat.parse.quoted(df, 'ResponseId', 'Q_47') # qiat.parse(df, ResponseId, Q_47) # # @returns data frame with parsed data, rows with NA or '' are omitted. qiat.parse.quoted = function(df, id, data){ # @TODO does not work? # if (is.factor(df[id])) stop(paste0(data, ' column must not be a factor')) filteredDF = df[df[,data]!='' & !is.na(df[,data]) ,] # parse data -> list of data data frames csvList = lapply(filteredDF[,data], function(str) tryCatch({ read.csv(text=str,stringsAsFactors = FALSE) }, error = function(err){ message('woa there is a malformed csv here') return(NA) } )) #browser() # add id to each data DF mask = which(sapply(csvList,nrow)>0) dataPages = mapply( function(id, df) cbind(id,df), filteredDF[mask,id], csvList[mask], SIMPLIFY = FALSE ) if (!length(dataPages)) { return(data.frame()) } # concat pages do.call(rbind,dataPages) } qiat.parse = function(df, id, data){ qiat.parse.quoted(df, deparse(substitute(id)), deparse(substitute(data))) } df = read.csv(paste(dir, 'examplePriming-update.csv',sep = '\\')) df <- df[which(grepl('block', df$Q2)),] library(kutils) df$ep <- mgsub(df$Q2, pattern = c('""'), replacement = c('"')) df2 <- qiat.parse.quoted(df = df, id='ResponseId', data = 'ep') nrow(df2) names(df2) table(df2$block, exclude=NULL) table(df2$cond, exclude=NULL) df2$prime <- ifelse(grepl('Black', df2$cond), 'black', ifelse(grepl('White', df2$cond), 'white', NA)) table(df2$prime) df2$target <- ifelse(grepl('Unpleasant', df2$cond), 'bad', ifelse(grepl('Pleasant', df2$cond), 'good', NA)) table(df2$target) df2.correct <- df2[which(df2$err==0),] library(doBy) ep.means <- summaryBy(formula = rt ~ id + prime + target, data = df2.correct) summaryBy(formula = rt.mean ~ prime + target, data = ep.means, FUN = c(mean, sd, median))