Remove Header from Data in R (Example)


In this article you’ll learn how to delete the column names from a data frame or matrix in the R programming language.

Table of contents:

Let’s just jump right in…


Creation of Example Data

To start with, we need to define some example data:

data <- data.frame(x1 = 2:7,    # Create example data
                   x2 = 9:4,
                   x3 = "s")
data                            # Print example data


table 1 data frame remove header from data


Have a look at the table that got returned after executing the previous R code. It shows that our example data consists of six rows and three columns with the column names x1, x2, and x3.


Example: Delete Column Names of Data Frame Using names() Function

In this example, I’ll show how to remove the column names from our data frame in R.

For this, we can use the names function and the NULL value as shown below:

names(data) <- NULL             # Delete column names
data                            # Print updated data


table 2 data frame remove header from data


As shown in Table 2, we have created a new data frame without header.


Video, Further Resources & Summary

Do you need further explanations on the R programming syntax of this post? Then you might have a look at the following video of my YouTube channel. I illustrate the R code of this article in the video.



Furthermore, you might want to have a look at the related articles of my website:


To summarize: This page has illustrated how to delete headers from a data table in the R programming language.

Note: In this tutorial, we have applied the example code to a data.frame object. However, we may use the same kind of R syntax to remove the header of a matrix.

Please tell me about it in the comments section, in case you have additional 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.

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.