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)

We can export our example data as CSV with the write.csv function:

write.csv(data, "data.csv")                         # write.csv with default specification

 

csv file with row names

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

 

csv file without with row names

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:

 

The YouTube video will be added soon.

 

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.

 



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.

Menu
Top