[R] error message: only first element in each line of matrix used

From: Melanie Ann Harsch <harschm_at_lincoln.ac.nz>
Date: Thu, 07 Jun 2007 10:36:47 +1200

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) {
      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_at_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. Received on Wed 06 Jun 2007 - 23:00:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 07 Jun 2007 - 02:31:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.