R - why it is better to use dim(x)[1] rather than nrow(x)

02 Jan 2018

It is more efficient to use dim(x)[1] to retrieve the number of rows rather than nrow(x) !

So to speed up your code, use dim(x)</code)>. Full explanation here:

https://www.r-bloggers.com/nrow-references-and-copies/

[ R  function  ]