OneBite.Dev - Coding blog in a bite size

insert an element at the end of an array in R

Code snippet on how to insert an element at the end of an array in R

  array <- c(1,2,3,4)
  array[length(array)+1] <- 5

This code is used to insert an element at the end of an array in R. First, it creates an array of values 1, 2, 3, and 4. Then the code adds an element 5 to the end of the array by assigning the value 5 to the (length of the array + 1) index. This adds the element to the end of the array (since the length of the array is 4, 5 will be assigned to the 5th index in the array). As a result, the array will contain the values 1, 2, 3, 4, and 5.

r