I guess, you could also do: names(dat1)[max.col(dat1)] #[1] "a" "b" A.K.
On Thursday, January 16, 2014 3:47 PM, arun <smartpink...@yahoo.com> wrote: Try: dat1 <- read.table(text="a b c d 1 0.5 0.1 0.2 0.2 5 0.3 0.5 0.1 0.1",sep="",header=TRUE) data.frame(Names=apply(dat1,1,function(x) names(x)[x %in% max(x)])) # Names #1 a #5 b #or colnames(dat1)[apply(dat1,1,which.max)] #[1] "a" "b" A.K. Hi, I need a small help... If I have a data frame like a b c d 1 0.5 0.1 0.2 0.2 5 0.3 0.5 0.1 0.1 I need the name of the column with the biggest number in each column. My results will be 1 a 5 b If I do apply(data.frame, 1, max) I have the maximum by row but I want the name, not the value... Thanks ______________________________________________ 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.