You can use a for
loop to add 1 to a numerical variable at each iteration in R. Here's an example:
main.r137 chars9 lines
In this example, we first create a numerical variable x
and set it equal to 0. We then use a for
loop to iterate through the values 1 to 5. At each iteration, we add 1 to x
using the +
operator, and then print the value of x
using the print()
function.
The output of this code will be:
main.r30 chars6 lines
Which shows that x
was incremented by 1 at each iteration of the loop.
gistlibby LogSnag