I have am trying to loop over a numeric vector. How do I do this? Typically in a for
loop one begins the loop with for(i in 1:z)
. However, I want something like for(i in vector)
. For example, see the below:
x <- c(839898, 3, 9)
for (i in x) { print(i) }
# Desired output
839898
3
9
In this instance, I do not want to vectorize
this as I am trying to learn how to accomplish this with a for
loop.
While this post is similar to many others, in almost all of the others I have seen only vectorized solutions because someone was trying to accomplish a task with minimal run time rather than learn how the loops work.