Rachit Agrawal
Rachit Agrawal

Reputation: 3343

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

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.

Upvotes: 19

Views: 26830

Answers (5)

code-freeze
code-freeze

Reputation: 485

read_csv('file_name.csv",check,names=F)

check.names=F, strips the white space character and removes the "x"

Upvotes: 0

Wayne
Wayne

Reputation: 1

I met the same problem. The solution for me on MAC machine is to save the file with fileEncoding = "macintosh". Then read it by doing check.names = F.

Upvotes: 0

Ramon
Ramon

Reputation: 31

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.

Upvotes: 3

count0
count0

Reputation: 2621

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.

Upvotes: 2

Metrics
Metrics

Reputation: 15458

according to @Joshua

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

Upvotes: 40

Related Questions