Remove First Row of Data Frame in R (Example)
In this article you’ll learn how to delete the first row of a data set in the R programming language.
The tutorial will contain the following content:
It’s time to dive into the example.
Introducing Example Data
Consider the exemplifying data below:
data <- data.frame(x1 = 1:5, # Creating example data x2 = LETTERS[1:5]) data # Printing example data # x1 x2 # 1 1 A # 2 2 B # 3 3 C # 4 4 D # 5 5 E
As you can see based on the previous output of the RStudio console, our exemplifying data is a data frame with two columns and five rows.
Example: Delete First Row of Data Frame
This Example shows how to remove the top row of a data frame in the R programming language. For this task, we have to subset our data so that the row at index position 1 is removed. We can do that by specifying – 1 within square brackets as shown below:
data_new <- data[- 1, ] # Remove first row data_new # Print updated data # x1 x2 # 2 2 B # 3 3 C # 4 4 D # 5 5 E
Have a look at the previous output: It’s showing the same data as before except the first row.
Video, Further Resources & Summary
Do you need more explanations on the topics of this tutorial? Then you may want to have a look at the following video of my YouTube channel. In the video, I explain the R programming code of this tutorial.
Additionally, you might have a look at the other articles which I have published on my website. You can find some other articles here.
- Conditionally Remove Row from Data Frame in R
- Remove Duplicated Rows from Data Frame in R
- Extract Subset of Data Frame Rows Containing NA in R
- The R Programming Language
To summarize: In this tutorial, I illustrated how to remove the top row of a data frame in R programming. In case you have additional questions, don’t hesitate to let me know in the comments. Furthermore, don’t forget to subscribe to my email newsletter for updates on the newest articles.