Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: removing the last elements of a vector

Tags:

r

vector

elements

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

like image 569
skan Avatar asked Sep 20 '10 17:09

skan


People also ask

How do I remove a value from a vector in R?

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.

How do I truncate a vector in R?

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.

How do I get the last element of a list 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.


1 Answers

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 
like image 190
Joshua Ulrich Avatar answered Sep 22 '22 05:09

Joshua Ulrich