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


  • 相关阅读:
    2021 0309-1 准备工作
    课程总结
    第十四周课程总结&实验报告
    第十三周课程总结
    第十二周课程总结
    第十一周课程总结
    第十周课程总结
    2019春总结作业
    第十二周作业
    第十一周作业
  • 原文地址:https://www.cnblogs.com/emanlee/p/8992668.html
Copyright © 2011-2022 走看看