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


  • 相关阅读:
    [Codeforces 1290C]Prefix Enlightenment
    [JLOI 2015]战争调度
    [APIO 2010]特别行动队
    [CEOI 2004]锯木厂选址
    [USACO 08MAR]土地购买
    [HNOI 2017]大佬
    [NOI 2011]NOI 嘉年华
    [SHOI 2013]超级跳马
    [NOI 2005]瑰丽华尔兹
    [SCOI 2010]股票交易
  • 原文地址:https://www.cnblogs.com/emanlee/p/8992668.html
Copyright © 2011-2022 走看看