dim, nrow & ncol Functions in R

The following R code explains how to inspect the dimensions of a data frame with the dim(), nrow(), and ncol() functions of the R programming language.

Example Data Frame

my_data <- data.frame(x = c(3, 1, 6, 3, 2),  # Create example data
                      y = "a",
                      z = c(2, 2, 1, 1, 2))
my_data                                      # Print example data
# x y z
# 3 a 2
# 1 a 2
# 6 a 1
# 3 a 1
# 2 a 2

Example: Application of dim, nrow & ncol Functions in R

The dimensions (i.e. the number of columns AND rows) are 5 and 3:

dim(my_data)                                 # Apply dim function
# 5 3

The number of rows is 5:

nrow(my_data)                                # Apply nrow function
# 5

The number of columns is 3:

ncol(my_data)                                # Apply ncol function
# 3

Example Video: nrow, ncol & dim Functions

YouTube

By loading the video, you agree to YouTube’s privacy policy.
Learn more

Load video

More Details on Inspecting the Dimensions of a Data Frame

YouTube

By loading the video, you agree to YouTube’s privacy policy.
Learn more

Load video

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top