OneBite.Dev - Coding blog in a bite size

loop array in R

Code snippet on how to loop array in R

for(i in 1:length(array)) {
  print(array[i])
}

This code is used to loop through an array in the R programming language. First, the for-loop is used to declare a variable i that starts with the first element of the array (1), and ends with the last element of the array (length(array)). The ‘print’ function is then used to print the value of each element one at a time - starting from the first element of the array (i=1) and ending with the last element of the array (i=length(array)).

r