Error while reading csv file in R

后端 未结 11 2121
自闭症患者
自闭症患者 2021-02-07 10:37

I am having some problems in reading a csv file with R.

 x=read.csv(\"LorenzoFerrone.csv\",header=T)

Error in make.names(col.names, unique = TRUE) : 
      inva         


        
相关标签:
11条回答
  • 2021-02-07 10:57

    You can always use the "Latin1" encoding while reading the csv:

     x = read.csv("LorenzoFerrone.csv", fileEncoding = "Latin1", check.names = F)
    

    I am adding check.names = F to avoid replacing spaces by dots within your header.

    0 讨论(0)
  • 2021-02-07 11:00

    This will read the column names as-is and won't return any errors:

    x = read.csv(check.names = F)
    

    To remove/replace troublesome characters in column names, use this:

    iconv(names(x), to = "ASCII", sub = "")
    
    0 讨论(0)
  • 2021-02-07 11:02

    Not sure if this is helpful, but I had a similar problem and figured out that it was because my "csv" file had a .csv suffix, but was actually a .xls file!

    0 讨论(0)
  • 2021-02-07 11:02

    I solved the problem by removing any graphical signs in the writing (i.e. accent marks). My headers were written in Spanish and had some accent marks in there. I replaced with simple words (México=Mexico) and problem was solved.

    0 讨论(0)
  • 2021-02-07 11:09

    Change the file format to - CSV UTF-8. It worked for me.

    0 讨论(0)
提交回复
热议问题