R语言 读取csv文件 解决分割符不能正确识别导致的错位现象 | 您所在的位置:网站首页 › r语言导入数据无法打开链接 › R语言 读取csv文件 解决分割符不能正确识别导致的错位现象 |
R语言 读取csv文件 解决分割符不能正确识别导致的错位现象
看到不少童鞋都遇到过类似问题。 使用python爬取了一些微博数据,存储在csv文件中: 读取后在Rstudio查看: 解决方案一 把csv、txt文件用别的工具(如notepad++)转成 ansi 编码的,然后再用read.csv命令去读。 缺陷:要手动去做 解决方案二 有博主指出是由于文件中文本双引号导致的问题,替换文件中的双引号为单引号即可。我没有试过,不知是否可行。 解决方案三 最简单的办法。直接使用fread()函数 library(data.table) df = fread(file = file_list[1],encoding = 'UTF-8') #file_list[1]是文件全目录读取后最后几列效果: Fast and friendly file finagler Description: Similar to read.table but faster and more convenient. All controls such as sep, colClasses and nrows are automatically detected. bit64::integer64 types are also detected and read directly without needing to read as character before converting. Dates are read as character currently. They can be converted afterwards using the excellent fasttime package or standard base functions. ‘fread’ is for regular delimited files; i.e., where every row has the same number of columns. In future, secondary separator (sep2) may be specified within each column. Such columns will be read as type list where each cell is itself a vector. |
CopyRight 2018-2019 实验室设备网 版权所有 |