OneBite.Dev - Coding blog in a bite size

loop object in R

Code snippet on how to loop object in R

  my_list <- c("Toy", "Car", "Bike")
  for (object in my_list) {
    print(object)
  }

This code will loop through the list of words named ‘my_list’, which includes “Toy”, “Car”, and “Bike”. The first line of the code creates an object called ‘my_list’, which contains the words to be looped. The for loop will then start, including the variable ‘object’ which will represent each of the items in the list. On each loop ‘object’ will represent one of the items in the list. The loop will print the value of ‘object’ each time it is looped; in this example, it will print “Toy”, “Car”, and “Bike”. The loop will end after looping through all the items in the list.

r