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
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.
names(data) <- NULL # Delete column names data # Print updated 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:
- Remove Duplicated Rows from Data Frame in R
- Remove Data Frame Columns by Name
- Remove All-NA Columns from Data Frame in R
- Clear Data Object from Workspace
- All R Programming Examples
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.