4  Data frame dimensions

Minimal Active Learning Setup Example

Author

E.D. Gennatas

Modified

July 1, 2024

4.1 Intro

One of the most basic operations when working with data is to get the dimensions of a dataset. This operation reports the number of rows and columns in the dataset.

4.2 Example

To get the dimensions of a data.frame in R we use the dim() function. For example, we can get the dimensions of the built-in iris dataset by running the following code. Click Run below and look at the output: it prints the number of rows, followed by the number of columns.

4.3 Practice

Your turn: Complete the following code to get the dimensions of the also built-in esoph dataset and assign it to a new object called esoph_dim:

Now, use the custom function check() to check your answer:

Solution:

esoph_dim <- dim(esoph)

When applied on a data.frame, like iris or esoph above, the dim() function returns the number of rows and number of columns, in that order.

For more information, see ?dim.