OneBite.Dev - Coding blog in a bite size

get the nth element of array in R

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

  my_array[n]

This code will return the nth element of the array named my_array. Arrays in R are numbered starting at 1 rather than 0, so the first item in an array is referred to as my_array[1], the second my_array[2], and so on. To get the nth element of the array, all you have to do is use the syntax my_array[n] and the nth element of the array will be returned. For example, if my_array is an array of numbers (1:10), then running my_array[5] will return the value 5.

r