OneBite.Dev - Coding blog in a bite size

get the first element of array in R

Code snippet on how to get the first element of array in R

  x[1]

This code snippet is used to get the first element of array ‘x’ in R. To access the first element of any array, simply write the name of the array followed by an open square bracket and the number 1(for first element) inside it and finally close the square bracket. In this case, the array ‘x’ is given and we are trying to get its first element. This code will return the first element of array ‘x’. Note that, if the array is a multi-dimensional array, the same code can be used to access the elements from the first dimension by providing the index of the element in the square brackets.

r