remove an element from the beginning of an array in r

To remove an element from the beginning of a one-dimensional array in R, you can use array indexing to subset the array, excluding the first element. Here's an example:

main.r
# create an example array
my_array <- c(1, 2, 3, 4, 5)

# remove the first element
my_array <- my_array[-1]

# check the result
print(my_array)  # output: [1] 2 3 4 5
167 chars
9 lines

In this example, we create an array my_array with values 1 through 5, and then remove the first element using array indexing. The resulting array my_array now contains only the elements 2 through 5.

gistlibby LogSnag