Created
          September 3, 2014 17:43 
        
      - 
      
- 
        Save alexstorer/96421ae18c2a3a28c8c3 to your computer and use it in GitHub Desktop. 
Revisions
- 
        alexstorer created this gist Sep 3, 2014 .There are no files selected for viewingThis file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,96 @@ df <- read.csv('~/Work/dkupor/hover/data.csv',header = F,stringsAsFactors=F) sumdf <- data.frame(rownum=numeric(), colheadtimes=numeric(), colheadnumber=numeric(), rowheadtimes=numeric(), rowheadnumber=numeric(), celltimes=numeric(), cellnumber=numeric() ) cheadernames <- c("A","B","C","D","E","F","G","H") rheadernames <- as.character(1:8) cellnames <- c() for (ch in cheadernames) { for (rh in rheadernames) { cellnames <- c(cellnames,paste(ch,rh,sep='')) } } rownum = 0 nrows = dim(df)[1] for (i in 1:nrows) { row = df[i,] # each row is a new participant rownum = rownum+1 sumdf[rownum,"rownum"] <- rownum chtimes = 0 chnumber = 0 rhtimes = 0 rhnumber = 0 celltimes = 0 cellnumber = 0 switchlateral = 0 switchvertical = 0 for (obs in strsplit(row,',')) { lastrow = "-1" lastcol = "-1" for (o in obs) { obsval = strsplit(o,':') obstime = as.numeric(obsval[[1]][2]) obscell = obsval[[1]][1] if (obscell=="undefined") { thiscol = "" thisrow = "" } else { thiscol = substring(obscell,1,1) thisrow = substring(obscell,2,2) if (thisrow=="") { if (thiscol %in% toupper(letters)) { } else { thisrow = thiscol thiscol = "" } } } if(obstime > 150 & !is.na(obstime)) { if (obscell %in% cheadernames) { chtimes = chtimes+obstime chnumber = chnumber+1 } if (obscell %in% rheadernames) { rhtimes = rhtimes+obstime rhnumber = rhnumber+1 } if (obscell %in% cellnames) { celltimes = celltimes+obstime cellnumber = cellnumber+1 } if (lastrow == thisrow) { switchlateral = switchlateral + 1 } if (lastcol == thiscol) { switchvertical = switchvertical + 1 } lastcell = obscell lastcol = thiscol lastrow = thisrow } } } sumdf[rownum,"colheadtimes"] = chtimes sumdf[rownum,"colheadnumber"] = chnumber sumdf[rownum,"rowheadtimes"] = rhtimes sumdf[rownum,"rowheadnumber"] = rhnumber sumdf[rownum,"celltimes"] = celltimes sumdf[rownum,"cellnumber"] = cellnumber sumdf[rownum,"switchlateral"] = switchlateral sumdf[rownum,"switchvertical"] = switchvertical } write.csv(sumdf,'sumdf.csv')