Introduction to R

7. Accessing specific elements of a dataframe

You can easily access specific rows or columns individually, or even specific elements, using the columns and row indices.  For example, to access the sixth subjects data alone:

data[6,]

or the sixth’s subjects BMI (column 11) only:

data[6,11]

Note the use of square brackets.

 

As discussed above, accessing a column can be done by name directly by referring to the column name directly using the <dataframe>$<variable> method.  For example, to access just the BMI column:

data$bmi