Subscripting and subsetting a dataset is an integral part of data manipulation. If we need to extract a smaller part of any R object (vector, data frame, matrix, or list) that contains more than one element, we need to use subscripts. Subscripting is an approach to access individual elements of an R object; for example, accessing a particular element of a vector. Usually, numeric integers are used for subscripting, but logical vectors can also be used for the same purposes. In R, the subscript starts from 1, and if we specify any negative subscript, it omits that position from the source object.
The following is an example of an R vector with 10 elements, and the effect of positive and negative subscripting:
# creating a 10 element vector num10 <- c(3,2,5,3,9,6,7,9,2,3) # accessing fifth element num10[5] [1] 9 # checking whether there is any value of num10 object greater # than 6 num10>6 [1] FALSE FALSE FALSE FALSE TRUE FALSE TRUE TRUE FALSE FALSE # keeping...