Indexing into a data structure

    Solution

    Elements from a vector, matrix, or data frame can be extracted using numeric indexing, or by using a boolean vector of the appropriate length.

    In many of the examples, below, there are multiple ways of doing the same thing.

    With a data frame:

    With the vector from above:

    Unlike in some other programming languages, when you use negative numbers for indexing in R, it doesn’t mean to index backward from the end. Instead, it means to drop the element at that index, counting the usual way, from the beginning.

    Also see .