“列多于列名"是什么意思?错误是什么意思? [英] What does the "More Columns than Column Names" error mean?

查看:484
本文介绍了“列多于列名"是什么意思?错误是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从IRS读取.csv文件,但它似乎没有以任何奇怪的方式进行格式化.

I'm trying to read in a .csv file from the IRS and it doesn't appear to be formatted in any weird way.

我正在使用read.table()函数,该函数我过去已经使用过几次,但是这次不起作用.相反,我收到此错误:

I'm using the read.table() function, which I have used several times in the past but it isn't working this time; instead, I get this error:

data_0910<-read.table("/Users/blahblahblah/countyinflow0910.csv",header=T,stringsAsFactors=FALSE,colClasses="character")

Error in read.table("/Users/blahblahblah/countyinflow0910.csv",  : 
  more columns than column names

为什么要这么做?

作为参考,可以在以下位置找到.csv文件:

For reference, the .csv files can be found at:

http://www .irs.gov/uac/SOI-Tax-Stats-County-to-County-Migration-Data-Files

(我需要的是在县到县迁移.csv部分下-流入或流出.)

(The ones I need are under the county to county migration .csv section - either inflow or outflow.)

推荐答案

它使用逗号作为分隔符.因此,您可以设置sep=","或仅使用read.csv:

It uses commas as separators. So you can either set sep="," or just use read.csv:

x <- read.csv(file="http://www.irs.gov/file_source/pub/irs-soi/countyinflow1011.csv")
dim(x)
## [1] 113593      9

该错误是由某些值中的空格和不匹配的引号引起的.标头中没有空格,因此read.table认为只有一列.然后,它认为在某些行中看到多个列.例如,前两行(标题和第一行):

The error is caused by spaces in some of the values, and unmatched quotes. There are no spaces in the header, so read.table thinks that there is one column. Then it thinks it sees multiple columns in some of the rows. For example, the first two lines (header and first row):

State_Code_Dest,County_Code_Dest,State_Code_Origin,County_Code_Origin,State_Abbrv,County_Name,Return_Num,Exmpt_Num,Aggr_AGI
00,000,96,000,US,Total Mig - US & For,6973489,12948316,303495582

和不匹配的引号,例如在第1336行(第1335行)上,这会使read.table与默认的quote参数(而不是read.csv)混淆:

And unmatched quotes, for example on line 1336 (row 1335) which will confuse read.table with the default quote argument (but not read.csv):

01,089,24,033,MD,Prince George's County,13,30,1040

这篇关于“列多于列名"是什么意思?错误是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆