To access a specific item in R, you can use indexing with square brackets []
. For example:
main.r82 chars4 lines
This code will create a vector my_vector
with values 1 through 5, and then extract the third element (which has the value 3) using indexing. The code will print the value of third_element
to the console.
You can also use indexing to change the value of a specific element in a vector:
main.r39 chars3 lines
This code changes the value of the fourth element in my_vector
from 4 to 10, and then prints the modified vector to the console.
gistlibby LogSnag