Dear list, I'm trying to query a string of numbers to identify where in the string the numbers stop increasing (where x[i] == x[i+1]). In example 1 below, I've adapted code from Jim Holt to do this. However, I run into situations where the condition is not met, as in example 2, where the number string is continuous. In this case, I need to specify an alternative outcome, where if in the loop this condition isn't met, I default to the max. of the number string which.max(x). Can someone tell me how to add an additional statement to example 2, specifying that if in the loop, the condition isn't found, then to give the max of the string? Thanks in advance for any replies ### Example 1 ################### start with test string xx <- c(3,4,5,5,6,7,8,9) result <- NULLx1 <- which.min(x)for(i in x1:(length(x)-1)) {if((x[i] == x[i+1])) result <- c(result, x[i]) # start with min, result = where in string x[i]==x[i+1]} ###Example 2 ####################################x <- c(3,4,5,6,7,8,9,10) result <- NULLx1 <- which.min(x)for(i in x1:(length(x)-1)) {if((x[i] == x[i+1])) result <- c(result, x[i]) # condition not met; result = NULL} [[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.