我有模拟看起来像这样的数据:错误read.fwf当标题= TRUE
LastName Date email CreditCardNum AgeZip Amount
Paul 21/02/14 [email protected] 4241033422900360 6738851$14.39
Bullock 2/7/[email protected] 5178789953524240 3336538$498.31
Mcmahon 11/5/[email protected] 5389589582467450 7734302$92.44
Walters 25/09/13 [email protected] 5157094536097720 7794007$206.60
Franco 17/06/13 [email protected] 345477952996264 2415873$89.12
,这是我正在试图将其导入到R,与头:
w <- c(11,10,57,16,3,5,8)
df <- read.fwf("data.txt",widths=w,stringsAsFactors=F)
names(df) <- df[1,]; df <- df[-1,]
我没有使用header=T
的原因是,它给我的错误:
Error in read.table(file = FILE, header = header, sep = sep, row.names = row.names, : more columns than column names
刚刚是不正确的。我知道宽度(w
)是正确的。那么这个错误来自哪里?我的解决方案工作正常,我只想了解发生了什么。
能否请您提供您的'w'载体,使这是(更多)重现? – jbaums
是的,对不起:'w < - c(11,10,57,16,3,5,8)'。编辑。 – shadowtalker
现在我有点不清楚你的问题是什么。你想知道为什么错误被抛出?或者你是在优雅的解决方案之后?你提出的指定'header = F'的方法似乎很好。 – jbaums