You can loop through all items in a vector called "test" and double each item using a for loop and multiplication operator in R. Here is an example code block:
main.r195 chars11 lines
In this example, the original vector "test" contains the values 1, 2, 3, and 4. The for loop iterates through each item in the vector and multiplies it by 2 using the multiplication operator "*", and the updated value is assigned back to the same index in the vector using the bracket notation. Finally, the updated vector is printed to the console. The output should be the vector 2, 4, 6, 8.
gistlibby LogSnag