4

When reading a csv, R automatically appends the letter X to syntactically invalid column names. For example:

> read.csv(text = "a,1,b")
[1] a  X1 b

How, can I append a different letter within the read.csv function when reading in the file, for example instead of 'X' appending 'foo' to give the output?:

[1] a  foo1 b
Sotos
  • 51,121
  • 6
  • 32
  • 66
pd441
  • 2,644
  • 9
  • 30
  • 41
  • Related: https://stackoverflow.com/questions/17548199/r-read-csv-adding-sub-script-x-in-header – LAP Nov 30 '17 at 10:22
  • I m not sure there is an argument in `read.csv` that lets you change that prefix. – Sotos Nov 30 '17 at 10:25
  • It seems to depend on `make.names()`, according to an answer [here](https://stackoverflow.com/questions/10441437/x-in-my-column-names-of-an-r-data-frame). `?make.names` does not show any way to change the default, though. – LAP Nov 30 '17 at 10:26
  • Also related - [Check if character value is a valid R object name](https://stackoverflow.com/questions/8396577/check-if-character-value-is-a-valid-r-object-name) – thelatemail Nov 30 '17 at 10:34

0 Answers0