Write Data Frame without Header in R (Example)

 

In this tutorial, I’ll show how to export a data frame without column names in R.

Table of contents:

With that, let’s get started…

 

Creation of Exemplifying Data

Consider the following example data:

data <- data.frame(x1 = 9:4,    # Create data frame
                   x2 = letters[10:15],
                   x3 = 9)
data                            # Print data frame to RStudio console
#   x1 x2 x3
# 1  9  j  9
# 2  8  k  9
# 3  7  l  9
# 4  6  m  9
# 5  5  n  9
# 6  4  o  9

Have a look at the previous output of the RStudio console. It shows that our example data has six rows and three columns. The variables of our data frame are called x1, x2, and x3.

 

Example: Exporting CSV File without Header Using write.table Function & col.names Argument

In this example, I’ll illustrate how to write a CSV file without column names.

For this, we have to use the write.table function. Within the write.table function, we have to specify the col.names argument to be equal to FALSE:

write.table(data,               # Write CSV file without header
            "data.csv",
            sep = ";",
            col.names = FALSE)

After running the previous R code, you should find a new CSV file called “data” in your working directory that looks like follows:

 

csv without header exported from r

 

Video, Further Resources & Summary

In case you need further information on the contents of this tutorial, you could have a look at the following video which I have published on my YouTube channel. In the video, I illustrate the R programming codes of this tutorial.

 

The YouTube video will be added soon.

 

In addition, you may want to have a look at the related R tutorials on this homepage. You can find some tutorials about exporting data below.

 

This post explained how to write a data frame without header in the R programming language. Don’t hesitate to let me know in the comments section below, if you have additional questions. Furthermore, please subscribe to my email newsletter in order to receive updates on the newest tutorials.

 

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.


2 Comments. Leave new

  • # Printing dataframe to RStudio console, controlling row names and column names

    # Create example data frame

    data <- data.frame(x1 = 9:4,
    x2 = letters[10:15],
    x3 = 9)

    # Print data frame to RStudio console with both row names and column names

    print(data)

    # x1 x2 x3
    # 1 9 j 9
    # 2 8 k 9
    # 3 7 l 9
    # 4 6 m 9
    # 5 5 n 9
    # 6 4 o 9

    # Print data frame without row names but with column names

    print(row.names=FALSE,data)

    # x1 x2 x3
    # 9 j 9
    # 8 k 9
    # 7 l 9
    # 6 m 9
    # 5 n 9
    # 4 o 9

    # Print data frame with row names but without column names

    unname(data)

    # 1 9 j 9
    # 2 8 k 9
    # 3 7 l 9
    # 4 6 m 9
    # 5 5 n 9
    # 6 4 o 9

    # Print data frame without row names and without column names

    print(row.names=FALSE,unname(data))

    # 9 j 9
    # 8 k 9
    # 7 l 9
    # 6 m 9
    # 5 n 9
    # 4 o 9

    Reply

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.

Top