Hello, > > I maybe missing something but this seems like an indexing problem > which doesn't require a loop at all. >
Yes, but with 'order'. # Original example input <- as.matrix(data.frame(a=c(5,1,3,7), b=c(2,6,4,8))) (input) desired.result <- as.matrix(data.frame(a=c(100,0,100,0), b=c(0,100,0,100))) (desired.result) all.equal(f(input), desired.result) # Two other examples set.seed(123) (x <- matrix(sample(10, 10), ncol=2)) f(x) (y <- matrix(sample(40, 40), ncol=5)) f(y) Hope this helps, Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/filling-the-matrix-row-by-row-in-the-order-from-lower-to-larger-elements-tp4538171p4538334.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.