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
Declare a boolean vector that has TRUE at all the positions you want to retain and FALSE at those you want to delete. Suppose that vector is y. Then, x[y] will give you the requires output.
Truncate function in R – trunc() trunc(x) is a truncate function in R, which rounds to the nearest integer in the direction of 0. trunc() function basically truncates the values in the decimal places. trunc() function is used in truncating the values of vector and truncating the values of a column in R.
First of all, create a list. Then, use tail function with sapply function to extract the last value of all elements in the list.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With