Data Frame Dimensions

nrow(___)
ncol(___)
dim(___)
length(___)
View Interactive Version

The number of rows and columns in a data frame can be guessed through the printed output of the data frame. However, it is much easier to get this information directly through functions. Additionally, you might want to use this information in some parts of the code.

Data frames have two dimensions. The number of rows is considered to be the first dimension. It typically defines the number of observations in a data set. To get the number of rows from the Davis data frame in the carData dataset use the nrow() function:

Input
nrow(Davis)
Output
[1] 200

Similarly, the number of columns or attributes of the data frame can be retrieved with ncol():

Input
ncol(Davis)
Output
[1] 5
Determine the size of a data frame