【问题标题】:R - read.csv add rows when loading the datasetR - read.csv 在加载数据集时添加行
【发布时间】:2015-08-06 08:58:01
【问题描述】:

我正在尝试读取 R 中的 .csv。一列中的某些行在双引号内包含带有逗号的文本:"example, another example" 但是当我尝试像这样读取它时,R 会改变行(它添加行):

steekproef <- read.csv('steekproef.csv', header = T, quote = "", sep = ',')

我在网上搜索时这个也不起作用:

steekproef <- read.csv('steekproef.csv', header = T, quote = "\"", sep = ',') 

这是错误信息:

steekproef <- read.csv("steekproef.csv", header = T, sep =",", quote ="\"")

comes with error:

Warning message:
In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
EOF within quoted string

Gives data.frame:      1391160 obs. of  29 variables


str(steekproef) gives no error but a

'data.frame':  3103620 obs. of  29 variables:


The dataset has 29 columns and 3019438 rows

【问题讨论】:

  • 我无法复制您的错误,可能我输入了不同格式的虚拟 csv 文件...

标签: r csv


【解决方案1】:

我认为问题不是由“例子,另一个例子”引起的:

我在 Excel 中创建了一个测试文件并将其保存为 .csv。在 Notepad++ 中是这样的:

test,num
"example, another example",1
"example, another example",2
example,3
example,4

我可以使用

毫无问题地导入它

steekproef&lt;- read.csv('steekproef.csv', header = T, sep = ',')

steekproef &lt;- read.csv('steekproef.csv', header = T, quote = "\"", sep = ',')

您的第一次尝试:steekproef &lt;- read.csv('steekproef.csv', header = T, quote = "", sep = ',') 给了我Error in read.table(file = file, header = header, sep = sep, quote = quote,: duplicate 'row.names' are not allowed

【讨论】:

    猜你喜欢
    • 2021-12-10
    • 2016-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 2011-03-08
    • 2013-10-30
    • 2010-11-28
    相关资源
    最近更新 更多