These extra x
are added in the csv file. I want these header without the x
. I'm importing a csv file into R using read.csv()
the file is being read but extra character is included in the header as is it numeric. How to remove this extra character?
Asked
Active
Viewed 114 times
1

Darren Tsai
- 32,117
- 5
- 21
- 51

Kiran
- 23
- 3
2 Answers
0
You can rename row.names of the element you imported. If the onlly thing you want to do is delete the first string of each name, you can do this (lets call your dataset df
):
colnames(df) <- substring(colnames(df),2)

R18
- 1,476
- 1
- 8
- 17
0
The extra 'X'
are added to the header because the original column names are not syntactically valid variable names. A legitimate column name has to start with a letter or the dot not followed by a number. By default read.csv()
will check the names of the variables in the data frame to ensure validity of names. You can switch off this feature through
read.csv(..., check.names = FALSE)

Darren Tsai
- 32,117
- 5
- 21
- 51