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


  • 相关阅读:
    win7安装mysql解压缩版
    PCA原理
    通俗理解协方差
    python GIL
    yield理解
    python super 的正确理解
    python常见面试题
    python 的特殊方法 __str__和__repr__
    springMvc REST 请求和响应
    Math.Round 四舍五入问题 解惑 !
  • 原文地址:https://www.cnblogs.com/emanlee/p/8992668.html
Copyright © 2011-2022 走看看