R Language’s most powerful feature is indexing feature. Indexing feature plays an essential role to represent the data. During the data analysis stage its vital to extract and manipulate subset of the data.
Subsetting a Vector
The basic object of R is a vector. To extract the elements can use ’[’ operator.
Not only one element, using ’[’ operator we can extract multiple elopements from the vector.
Use of negative indices
Use of logic
Subsetting a Matrix
Matrix can be subsetted in the usual way with their row and column indices.
Accessing the row=1 and col=2.
Accessing the element using matrix indices points row=2,col=3 and row=1,col=1.
While extracting the element from a matrix we would have seen in the above code the Matrix dimension has dropped. But during subsetting the object we have the option to turnoff by setting drop =FALSE.
Subsetting a list is almost like vectors. Since list can contain different objects within the list, to extract the elements we should use [[ or $ operator.
Subsetting Data Frames
It similar to matrix, we need using the indices of row and column.