the error message means (most likely) that srOne[row, "timestamp"] has NA as a value. Put
options(error = recover) in your script so that you get control at the point of the error and can then use 'browser' (?browser) to examine the values. It is a problem with your data and probably the result of some calculation that you will have to track down. Sent from my iPad On Mar 10, 2013, at 17:32, Louis <louisv...@gmail.com> wrote: > I am having trouble with this code: > > trOne <- read.csv("*.csv", header=TRUE) > srOne <- read.csv("*/SRdivision1.csv", header=TRUE) > row = 1 > > for (g in 1:162) { > e = trOne[g, "END_TIME"] > s = trOne[g, "START_TIME"] > q = trOne[g, "OCC_TIME"] > r = trOne[g, "R_TIME"] > gazeSum = 0 > n = 0 > print(g) > > while (s <= e) { > > if (srOne[row, "timestamp"] == 670920) { > print(srOne[row, "timestamp"]) } > > if (r == srOne[row, "timestamp"] ) { > trOne[g, "R_EYE_POS"] = srOne[row, "LEFT_GAZE_X"] } > > if (q == srOne[row, "timestamp"] ) { > trOne[g, "OCC_EYE_POS"] = srOne[row, "LEFT_GAZE_X"] } > > if (s >= q & s <= r) { > gazeSum = gazeSum + as.double(srOne[row, "LEFT_GAZE_X"]) > n = n + 1 } > > s = s + 1 > row = row + 1 > } > trOne[g, "AVG_EYE_POS"] = gazeSum / n > } > > The code runs well, but there is an issue with this: > Error in if (srOne[row, "timestamp"] == 670920) { : > missing value where TRUE/FALSE needed > > That is just a line for debugging, but it means the if statement below it > isn't working right if I get the error. It only does this when I write to > file. The only unique thing in this case is that I know the line with > 670920 as the timestamp has the Left_Gaze_X as 0 (as it should be) but the > comparison being made is screwy after this row. The error shows up at this > line, which is when g = 162. I have another file I used to get the rest of > my data (SRDivision2), it calculates that incorrectly, Everything works > fine before g = 162, though. > > After 162, when I make g 163:165, the Left_Gaze_X is correct, but when I > set Occ_Eye_Pos equal to it, it equals a totally different number. For > instance, the Gaze outputs as 488.3 when I print it, but when I set > Occ_Eye_Pos equal to it, the value of Occ_Eye_Pos is 2838... > > Anyone know what's going on with this? > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.