[R] Help

arun smartpink111 at yahoo.com
Mon Feb 10 17:08:23 CET 2014

mat1 <- matrix(sample(40,5*3,replace=TRUE),ncol=3)

mat2 <- apply(mat1,1,sort,decreasing=TRUE)
 mat2[1,]- mat2[2,]

Thank you. 

And if I have a lot of rows? How can I apply this for row? 

On Sunday, February 9, 2014 8:20 PM, arun <smartpink111 at yahoo.com> wrote:
Based on the data.

vec1 <- c(56,98,15)
vec2 <- sort(vec1,decreasing=TRUE)
#[1] 42


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 

How can I do this in R? To obtain the max I used  apply(data, 1, max), but...and the other? 


More information about the R-help mailing list