You want to try cummax
:
> d[ d[,2] == cummax(d[,2]) ,]
[,1] [,2]
[1,] 1 1
[2,] 2 11
[3,] 3 21
[4,] 4 60
[5,] 7 61
[6,] 11 63
PS. data
is an internal R
function, so, since R
variables and functions share the namespace (R
design was influenced by Scheme, which is a "Lisp-1"), your variable shadows the system function.