Hi, A function calculates the absolute difference between the two largest values of each row of a matrix, as shown in the following example code: cx <- matrix(runif(15),5) cy <- t( apply(cx, 1, order, decreasing=TRUE) ) cz <- rep(0, nrow(cx)) for( i in 1:nrow(cx) ) cz[i] <- abs(diff(cx[i, cy[i,1:2]])) Anybody has any ideas on how the last loop can be vectorized?
Thanks. Christos Hatzis, Ph.D. Nuvera Biosciences, Inc. 400 West Cummings Park Suite 5350 Woburn, MA 01801 Tel: 781-938-3830 www.nuverabio.com <http://www.nuverabio.com/> ______________________________________________ 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.