Hi,

I need to extract the second largest element from each row of a
matrix. Below is my solution, but I think there should be a more efficient
way to accomplish the same, or not?


 set.seed(1)
 a <- matrix(rnorm(9), 3 ,3)
 sec.large <- as.vector(apply(a, 1, order, decreasing=T)[2,])
 ans <- sapply(1:length(sec.large), function(i) a[i, sec.large[i]])
 ans

Thanks in advance for your help,
Lars.

	[[alternative HTML version deleted]]

