Let us start by creating the vector
# We will create a vector that includes 6 elements, and we will name the vector x
x <- c(1,5,77,34,23,12)
#Let us see how the vector looks
x
## [1] 1 5 77 34 23 12
#Let us call the first element in vector x
x[1]
## [1] 1
#Let us call the second element
x[2]
## [1] 5
#Let us call the first through the third elements
x[1:3]
## [1] 1 5 77
What if we want to call non-consecutive elements in vector x? (this is the question that was asked in class)
# In order to call non-consecutive elements in vector x, you need to create another vector that specifies the locations of those elements and put it the brakets of vector x
# Let us say you would like to call the frist and fourth elements
x[c(1,4)]
## [1] 1 34
If you write x[1,4] without the function c, you will get an error
#Let us call the second and the sixth elements
x[c(2,6)]
## [1] 5 12
Thank you for asking questions and adding value to the calss :)