Export CSV File without Row Names in R (Example)
In this tutorial you’ll learn how to export a csv file without row names in R.
Table of contents:
So without further additions, let’s just jump right in.
Creation of Example Data
We will use the following data frame as example data in this tutorial:
data <- data.frame(x1 = rep("A", 5), # Create example data x2 = "X", x3 = 5:9) |
data <- data.frame(x1 = rep("A", 5), # Create example data x2 = "X", x3 = 5:9)
We can export our example data as CSV with the write.csv function:
write.csv(data, "data.csv") # write.csv with default specification |
write.csv(data, "data.csv") # write.csv with default specification
Table 1: Exported CSV-File with Row Names.
Table 1 shows the output of the write.csv function. A CSV-file with row names.
Example: write.csv without Row Names
In case we want to export a CSV-file without row names from R to our directory, we can use row.names argument of the write.csv R function. We simply have to specify row.names = FALSE:
write.csv(data, "data.csv", row.names = FALSE) # Specify row.names = FALSE |
write.csv(data, "data.csv", row.names = FALSE) # Specify row.names = FALSE
Table 2: Exported CSV-File without Row Names.
Table 2 shows our new CSV-file: It contains our data without row names.
Video & Further Resources
I have recently published a video tutorial on my YouTube channel, which explains the R programming syntax of this article. You can find the video below:
Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.
If you accept this notice, your choice will be saved and the page will refresh.
In addition, I can recommend to read the other RStudio articles of my website:
In this article you learned how to prevent R from writing row names to an exported CSV-file in the R programming language. Let me know in the comments, in case you have further questions.