First, your code has flaws in the assignment of NA and in passing na.rm=TRUE to colMeans().
It should be: test2 <- test for (i in 1:ncol(test)) { test2[which.min(test[,i]),i]=NA} print(test2) samp1 samp2 samp3 1 60 60 NA 2 50 60 65 3 NA 90 65 4 90 NA 90 print(colMeans(test2,na.rm = TRUE)) samp1 samp2 samp3 66.66667 70.00000 73.33333 For your purpose, I suggest the following: apply(test, 2, function(x) { mean(x[-which.min(x)])}) GG [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.