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

Melanie Ann Harsch harschm at lincoln.ac.nz
Thu Jun 7 00:36:47 CEST 2007


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) }
		  }}



More information about the R-help mailing list