Delete Last Vector Element of Vector in R (Example Code)

This tutorial illustrates how to remove the values at the end of a vector in the R programming language.

Creating Example Data

x <- 1:5                         # Example vector in R
x                                # Display example vector in RStudio console
# [1] 1 2 3 4 5

Example: Removing Last Element of Vector Using head() Function

head(x, - 1)                     # Delete last vector element
# [1] 1 2 3 4

Further Resources & Related Articles

Here, you may find some additional resources on topics such as vectors, numeric values, and loops.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed