views:

131

answers:

4

Hello

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

+2  A: 

Just use the numeric indices, ie

 n <- nrow(X)
 X <- X[1:(N-100-1),]

where you should need to ensure N is larger 100 etc

Dirk Eddelbuettel
A: 

if you're a one liner

x = x[1:(length(x) -101)]
Arthur Rizzo
With all your answers I've built almost what I needcoredata(zz2) <- c(rep(0,3),head(coredata(zz),-3))Now I just need to use it inside a zoo series with several columns, modifying just one.
+5  A: 

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
Joshua Ulrich
A: 

Hi thanks What I really need is a little bit more complicated. I need to shift the series, removing some elements and adding other from the other side but when I do c(rep(0,10),x[1:(length(x)-11)]) it's not zoo any more.

cheers

This is an entirely different question. If what you _really_ needed was more complicated, why didn't you say so in your _original_ question? `?lag.zoo` answers this question.
Joshua Ulrich