OneBite.Dev - Coding blog in a bite size

remove item from array in R

Code snippet on how to remove item from array in R

  test_array <- c(1,2,3,4,5,6)
  test_array <- test_array[-3]

This code creates an array named ‘test_array’ with 6 values from 1 to 6. The second line uses the ‘minus’ sign to remove the 3rd element from the array ‘test_array’, so after running the code the values in ‘test_array’ will only be 1,2,4,5,6. The ‘minus’ sign has the effect of deleting the specified element, in this case the 3rd one, from the array and repopulating the array with only the untouched values.

r