drop Function in R (Example)
This tutorial demonstrates how to remove redundant dimension information using the drop function in the R programming language.
Table of contents:
It’s time to dive into the example:
Creation of Example Data
The following data is used as basement for this R tutorial:
mat <- matrix(1:4, ncol = 4) # Create example matrix mat # Print example matrix

Table 1 shows that the example data is a matrix object that contains one row and four integer columns.
Let’s check the dimensions of our matrix using the dim() function:
dim(mat) # Check dimensions # [1] 1 4
The dim function confirms what we have already seen in Table 1 – Our data has one row and four columns.
Example: Apply drop() Function to Matrix Object
This section explains how to get rid of unimportant dimensions using the drop command in R.
Let’s apply the drop function to our matrix object:
mat_drop <- drop(mat) # Apply drop function mat_drop # Return output of drop function # [1] 1 2 3 4
As you can see, our matrix with only one row was converted to a vector object.
We can confirm that we have removed the unnecessary dimensions by applying the dim function to our updated data object:
dim(mat_drop) # Check dimensions # NULL
The dim function returns NULL, i.e. no dimensions are left anymore.
In this example, we have applied the drop function to a matrix object. Please note that we could apply the drop function to an array as well.
Video & Further Resources
I have recently released a video on my YouTube channel, which explains the R syntax of this tutorial. You can find the video below:
In addition to the video, you may want to read the related articles on my website.
- Set Row & Column Names of Data with Unknown Dimension
- Access Attributes of Data Object in R
- comment Function in R
- List of R Functions
- R Programming Language
In this R programming tutorial you have learned how to drop redundant extent information. Please tell me about it in the comments, if you have further questions.
Subscribe to the Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Welcome to the Statistics Globe newsletter. From now on, I’ll send you regular emails about statistics, data science, AI, and programming with R and Python.
I’m Joachim Schork. On this website, I provide statistics tutorials as well as code in Python and R programming.
Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe. I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Please check your email inbox and click the confirmation link to complete your subscription. If you don’t see the email within a few minutes, please also check your spam/junk folder.






