Delete the "X" in the Header in the R

2

I am importing a csv file into the R and the name of each column is showing the letter "X" before the original name. For example:
Field names in csv: 1.2_cidade ; 2_UF . Field names after import: X1.2_cidade ; X2_UF .

How do I import without the "X"?

    
asked by anonymous 02.02.2018 / 15:17

3 answers

4

Try to look at the argument check.names in ?read.csv .

read.csv("dados.csv", check.names = FALSE)
    
02.02.2018 / 15:57
1

You may be putting too many arguments in the read.csv function, I had this problem sometimes, when I put the quote argument, and etc, now I usually just write the command like this and it works out (my .csv files are saved with decimal separated by comma ), indicating that the separation of the columns is by ; and the decimal separates by , .

read.csv("nome_do_arquivo.csv",sep=";",dec=",")
    
15.02.2018 / 17:52
0

The problem is that R does not accept the variable, function, or column name of data.frame starting with numeric, period, or subtraction. So it adds X .

data <- data.frame('1.2_cidade' = c(1:2), '2_UF' = c(1:2))

data
   X_1.2_cidade X2_UF
1            1     1
2            2     2

The best solution is to rename the columns without the X , numbers, period, or subtrace, for even forcing you may have invocation problems at some point.

colnames(data) <- sub("^[X0-9._]+", "", colnames(data))

data
  cidade UF
1      1  1
2      2  2
    
05.02.2018 / 16:33