I have a matrix and am trying to write a code to 1. identify all neg values along each line 2. for each neg value I need to identify min(j+3) 3. end with this code: eq[i,j]<- ifelse(mat.r[i,j] < (0.5*mat.s[i,j]), mat.all[i,j], 0)
This is the code I have so far. I have tried several different methods but I keep getting the same error message that the condition has length >1 and only the first element will be used. Any suggestions? int <- 3 for(i in 1:nrow(mat.all)) { start.year <- min(which(is.na(mat.all[i,])==F & (mat.all[i,]<0))) fin.year <- max(which(is.na(mat.all[i,])==F)) for(j in start.year:fin.year) { if(mat.all[i,(j-int):(j-1)]<0){ mat.s[i,j] <- ifelse((mat.all[i,(j-int):(j-1)])==pmin, mat.all[i,j], 0); mat.r [i,j] <- which.max((mat.all[i,(j+1):(j+int)]) > 0) } }} ______________________________________________ R-help@stat.math.ethz.ch 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.