Index in the vector is used to give the element at that position of the vector. Few programming languages start the index with 0, and the other starts at 1. R counts the index from 1. There are many possibilities while putting an index number i.e. 1. Positive and in range index > x<- (1,3,4,5) > x[2] [1] “3” 2. Out of range
>x <- (2,3,4,5) > x[110] [1] NA 3. Negative index- removes this element and replies back with all the left numbers. > x <- (3,4,5,6,7) > x[-3] [1] “3” “4” “6” “7” 4. Range of values >x <- (3,4,5,6,7,8) > x[2:5] [1] “4” “5” “6” “7” 5. Duplicate index >x <- (3,4,5,6,7) >s[c(2,1,2,3)] [1] “4” “3” “4” “5” 6. Logical index If we want to select a particular group of an index number, then you should use logical operators i.e., TRUE and FALSE
> x <- (2,3,4,5,6) > s[c(TRUE, FALSE, FALSE, TRUE, TRUE) [1] “2” “5” “6”