R: read.csv adding sub-script "X" in header

23,265

Solution 1

according to @Joshua

read.csv("filename.csv",check.names=FALSE)

Solution 2

I had the same issue on my Mac. There was a X... at the beginning of the first variable. The problem was that the CSV file was actually a CSV UTF-8 (Comma delimited) file. Saving the file as a CSV (Comma separated values) solved it.

Solution 3

Using the quote="" option will also prepend an X. for each column of your data.frame. If you can, try to remove that from your read.csv options, else add the check.names=F option which will override that behavior.

Share:
23,265

Related videos on Youtube

Rachit Agrawal
Author by

Rachit Agrawal

Love coding.

Updated on July 05, 2022

Comments

  • Rachit Agrawal
    Rachit Agrawal almost 2 years

    I have a data frame that has headers as this

    Name  0x1  1x2
    

    read.csv changes the header to be

    Name X0x1 X1x2
    

    Is there a way, where this can be avoided?

    Thanks.

    • Joshua Ulrich
      Joshua Ulrich almost 11 years
      Read ?read.csv, where it describes the check.names argument.
    • Roland
      Roland almost 11 years
      And be warned that there are good reasons that read.table and friends sanitize the names.
  • Super_John
    Super_John almost 6 years
    someone please tell me why that worked. I've spend 2 hours on this and 20 stack overflow postings. This is insane.