We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Firefox.

Selecting the bottom of a data frame

head(___, n = ___)
tail(___, n = ___)
View Interactive Version

The tail() function can be used to select the bottom rows of a data frame. Similar to the head() function it also accepts a parameter n to specify the number rows to be returned.

For example, to select the last five rows from the TitanicSurvival dataset you can write:

tail(TitanicSurvival, n = 5)
                          survived    sex  age passengerClass
Zabour, Miss. Hileni            no female 14.5            3rd
Zabour, Miss. Thamine           no female   NA            3rd
Zakarian, Mr. Mapriededer       no   male 26.5            3rd
Zakarian, Mr. Ortin             no   male 27.0            3rd
Zimmerman, Mr. Leo              no   male 29.0            3rd

The head and tail functions can also be combined to select a fragment of the data set from the middle. To select the first five rows from the bottom 500 rows you can write:

head(tail(TitanicSurvival, n = 500), n = 5)
                                survived    sex age passengerClass
Ford, Mr. Edward Watson               no   male  18            3rd
Ford, Mr. William Neal                no   male  16            3rd
Ford, Mrs. Edward (Margaret Ann       no female  48            3rd
Fox, Mr. Patrick                      no   male  NA            3rd
Franklin, Mr. Charles (Charles        no   male  NA            3rd