Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set.seed(1234)
- M = matrix(sample(20,20), ncol=4)
- M
- [,1] [,2] [,3] [,4]
- [1,] 3 10 7 9
- [2,] 12 1 5 17
- [3,] 11 4 20 16
- [4,] 18 8 15 19
- [5,] 14 6 2 13
- t(apply(M, 1, function(x) head(order(x),3)))
- [,1] [,2] [,3]
- [1,] 1 3 4
- [2,] 2 3 1
- [3,] 2 1 4
- [4,] 2 3 1
- [5,] 3 2 4
Add Comment
Please, Sign In to add comment