HI, By running your code: on the example dataset:
mat<- structure(c(0.8959863, 0.8951168, 0.8971445, 0.8962497, 0.8963061, 0.8973174, 0.8986438, 0.8964609, 0.8975849, 0.8965599, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), .Dim = c(10L, 2L), .Dimnames = list( NULL, c("trace", "iterations"))) while(nrow(mat) > 1){ high <- diff(mat[, 'trace']) > 0 if (!any(high)) break # done # find which one to delete delete <- which.max(high) + 1L mat <- mat[-delete,, drop=FALSE] } Couldn't reproduce the error. mat # trace iterations #[1,] 0.8959863 1 #[2,] 0.8951168 2 ----- Original Message ----- From: Laz <lmra...@ufl.edu> To: r-help@r-project.org Cc: Sent: Saturday, September 14, 2013 4:44 PM Subject: [R] Error in Loop Hi, I have a matrix given by: >mat trace iterations [1,] 0.8959863 1 [2,] 0.8951168 2 [3,] 0.8971445 3 [4,] 0.8962497 4 [5,] 0.8963061 5 [6,] 0.8973174 6 [7,] 0.8986438 7 [8,] 0.8964609 8 [9,] 0.8975849 9 [10,] 0.8965599 10 I want to use the code below: It keeps the first observation but compares all the rest with the earlier one and drops the one that is larger and it continues until all the rows are done. while(nrow(mat) > 1){ high <- diff(mat[, 'trace']) > 0 if (!any(high)) break # done # find which one to delete delete <- which.max(high) + 1L mat <- mat[-delete,, drop=FALSE] } The error I get is " Error in r[i1] - r[-length(r):-(length(r) - lag + 1L)] : non-numeric argument to binary operator" How do I fix it? Laz [[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.