R: removing the last elements of a vector

skan picture skan · Sep 20, 2010 · Viewed 64.7k times · Source

How can I remove the last 100 elements of a zoo series?

I know the name[-element] notation but I can't get it work to substract a full section

Answer

Joshua Ulrich picture Joshua Ulrich · Sep 20, 2010

I like using head for this because it's easier to type. The other methods probably execute faster though... but I'm lazy and my computer is not. ;-)

x <- head(x,-100)
> head(1:102,-100)
[1] 1 2