Using which() improves my code, but now I'm receiving some data.frame error and still does not convert the values to negative.
#TAKE PART OF MATRIX CEM1_PARTIAL <- CEM1[1:10,1:10] #CEM1_PARTIAL=apply(CEM1_PARTIAL,2,as.character) #CEM1_PARTIAL <- as.numeric(as.character(CEM1_PARTIAL)) #CEM1_PARTIAL[which(CEM1_PARTIAL$V4 == "DOWN") - 1] <- CEM1_PARTIAL$V3[which(CEM1_PARTIAL$V4 == "DOWN") - 1] * -1 for(j in 1:ncol(CEM1_PARTIAL)) { for(i in 1:nrow(CEM1_PARTIAL)) { CEM1_PARTIAL[which(CEM1_PARTIAL[i,j] == "DOWN")] = CEM1_PARTIAL[which(CEM1_PARTIAL[i,j] == "DOWN")-1] * -1 } } Error in data.frame(value, row.names = rn, check.names = FALSE, check.rows = FALSE) : row names supplied are of the wrong length -- View this message in context: http://r.789695.n4.nabble.com/matrix-looping-accessing-previous-column-tp3165308p3165380.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.