-2

I have two vectors x and y.

    x = c(2, 4, 6, 3, 1.5)
    y = c(2.2, 1, .5)
    m = matrix(c(x, y, rep(0, length(x)), rep(1, length(y))), 
    nrow = 2, ncol= length(x) + length(y), byrow = TRUE)

How can I sort the second row of matrix m according to sort of first row of matrix min R?

    > res
   [1] 1 1 0 0 1 0 0 0
rose
  • 1,971
  • 7
  • 26
  • 32

1 Answers1

1

You are looking for order. Understanding the order() function explains some of the details

m[2,order(m[1,])]
Community
  • 1
  • 1
mnel
  • 113,303
  • 27
  • 265
  • 254