[R] Method

Karl Ove Hufthammer karl at huftis.org
Tue Nov 24 16:35:04 CET 2009


On Tue, 24 Nov 2009 10:14:18 -0500 Sarah Goslee <sarah.goslee at gmail.com> 
wrote:
> x <- runif(45)   # make a test vector
> length(x)         # position of the last element
> x[length(x)]     # value of the last element

For the last one, this should be even better: tail(x, 1)

But, actually benchmarking this, it turns out that the 'length' solution 
is about 10 times faster than the 'tail' solution. :-(

-- 
Karl Ove Hufthammer




More information about the R-help mailing list