Rstudio read.csv()读取文件错误:列的数目比列的名字要多

今天刚开始学习R 

安装Rstudio后 使用read.csv()读取文件内容,代码如下:

movie <- read.csv(file = "douban_movie_clean.txt",  sep = "^", header = TRUE)

报错:

Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
  列的数目比列的名字要多

多方查找之后找到:可能是因为文本的编码不是utf-8造成的

解决方法:添加一条fileEncoding = "utf-8"

movie <- read.csv(file = "douban_movie_clean.txt",  sep = "^", header = TRUE, fileEncoding = "utf-8")

会报一个warning,但能够正确执行。

猜你喜欢

转载自blog.csdn.net/qq_25406563/article/details/81264857