create function to print numbers 1 to 10 in r

You can create a function in R to print numbers 1 to 10 using a loop. Here's an example:

main.r
print_numbers <- function() {
  for (i in 1:10) {
    print(i)
  }
}

print_numbers()
86 chars
8 lines

In this code, the print_numbers function uses a for loop to iterate over numbers 1 to 10. Inside the loop, each number is printed using the print function. Finally, you can call the print_numbers function to execute the loop and print the numbers 1 to 10.

related categories

gistlibby LogSnag