Based on the data. vec1 <- c(56,98,15) vec2 <- sort(vec1,decreasing=TRUE) ?vec2[1]-vec2[2] #[1] 42 A.K. Hi, I need some help in a simple thing.... If I have 3 classes like ? ?56 ? ? 98 ? ?15, I need do max1-max2 where the max 1 is the maximun (98) and the max2 is the second maximun (56)... How can I do this in R? To obtain the max I used ?apply(data, 1, max), but...and the other? Thanks