zoukankan      html  css  js  c++  java
  • Read.csv: some rows are missing

    read.csv in R doesn't import all rows from csv file

    The OP indicates that the problem is caused by quotes in the CSV-file.

    When the records in the CSV-file are not quoted, but only a few records contain quotes. The file can be opened using the quote="" option in read.csv. This disables quotes.

    data <- read.csv(filename, quote="")

    Another solution is to remove all quotes from the file, but this will also result in modified data (your strings don't contain any quotes anymore) and will give problems of your fields contain comma's.

    lines <- readLines(filename)
    lines <- gsub('"', '', lines, fixed=TRUE)
    data <- read.csv(textConnection(lines))

    A slightly more safe solution, which will only delete quotes when not just before or after a comma:

    lines <- readLines(filename)
    lines <- gsub('([^,])"([^,])', '\1""\2', lines)
    data <- read.csv(textConnection(lines))



    REF:
    https://stackoverflow.com/questions/26094584/read-csv-in-r-doesnt-import-all-rows-from-csv-file


  • 相关阅读:
    JSOI2015 总结
    JSOI2014 总结
    JSOI2010/2011 总结
    1.13 考试总结
    1.15 考试总结
    [SDOI2015]寻宝游戏
    [教程]视频网课如何打开倍速纵享丝滑
    对机器学习的一些理解【学术篇】
    angular JS 路由功能
    理解 $scope
  • 原文地址:https://www.cnblogs.com/emanlee/p/8992668.html
Copyright © 2011-2022 走看看