所描述的具有多个“\n”的极长项目的症状表明您可能需要处理不匹配的引号。如果名称或地址条目中有引号,则解析器将等待下一个,然后再考虑条目完成。尝试”
x=read.csv("test1.csv", header = FALSE, sep="'", quote="")
这实际上对我下载的文件不起作用。 (并且请注意, sep 参数将被忽略read.csv
。)我需要首先使用 count.fields 和该分隔符,然后使用read.table
with fill =TRUE
。结果仍然有点混乱,几列都用逗号填充,但至少有一些东西可以处理:
table( count.fields("~/Downloads/test1.txt", sep="'", quote=""))
10 13
5 130
x <- read.table("~/Downloads/test1.txt", header = FALSE, sep="'", quote="", stringsAsFactors=FALSE, skip=5)
#Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
# line 6 did not have 13 elements
x <- read.table("~/Downloads/test1.txt", header = FALSE, sep="'",
quote="", stringsAsFactors=FALSE, fill=TRUE)
str(x)
#########################################################
'data.frame': 135 obs. of 13 variables:
$ V1 : chr "INSERT INTO message VALUES (52," "INSERT INTO message VALUES (53," "INSERT INTO message VALUES (54," "INSERT INTO message VALUES (55," ...
$ V2 : chr "[email protected] /cdn-cgi/l/email-protection" "[email protected] /cdn-cgi/l/email-protection" "[email protected] /cdn-cgi/l/email-protection" "[email protected] /cdn-cgi/l/email-protection" ...
$ V3 : chr "," "," "," "," ...
$ V4 : chr "2000-01-21 04:51:00" "2000-01-24 01:37:00" "2000-01-24 02:06:00" "2000-02-02 10:21:00" ...
$ V5 : chr "," "," "," "," ...
$ V6 : chr "<12435833.1075863606729.JavaMail.evans@thyme>" "<29664079.1075863606676.JavaMail.evans@thyme>" "<15300605.1075863606629.JavaMail.evans@thyme>" "<10522232.1075863606538.JavaMail.evans@thyme>" ...
$ V7 : chr "," "," "," "," ...
$ V8 : chr "ENRON HOSTS ANNUAL ANALYST CONFERENCE PROVIDES BUSINESS OVERVIEW AND GOALS FOR 2000" "Over $50 -- You made it happen!" "Over $50 -- You made it happen!" "ROAD-SHOW.COM Q4i.COM CHOOSE ENRON TO DELIVER FINANCIAL WEB CONTENT" ...
$ V9 : chr "," "," "," "," ...
$ V10: chr "HOUSTON - Enron Corp. hosted its annual equity analyst conference today in==20Houston. Ken Lay, Enron chairman and chief execu"| __truncated__ "On Wall Street, people are talking about Enron. At Enron, we re talking=20about people...our people. You are the driving forc"| __truncated__ "On Wall Street, people are talking about Enron. At Enron, we re talking=20about people...our people. You are the driving forc"| __truncated__ "HOUSTON =01) Enron Broadband Services (EBS), a wholly owned subsidiary of E=nron=20Corp. and a leader in the delivery of high-b"| __truncated__ ...
$ V11: chr "" "," "," "," ...
$ V12: chr "" "Robert_Badeer_Aug2000Notes FoldersPress releases" "Robert_Badeer_Aug2000Notes FoldersPress releases" "Robert_Badeer_Aug2000Notes FoldersPress releases" ...
$ V13: chr "" ");" ");" ");" ...
我使用逗号作为分隔符并仅使用单引号而不是默认的单引号或双引号得到了更好的结果read.*
- 函数使用:
x2 <- read.table("~/Downloads/test1.txt", header = FALSE, sep=",",
quote="'", stringsAsFactors=FALSE, fill=TRUE)
str(x2)