This related question points out a part of the ?read.table
documentation that explains your problem:
If there is a header and the first row contains one fewer field
than the number of columns, the first column in the input is used
for the row names. Otherwise if row.names is missing, the rows are numbered.
页: 1 可以通过使用以下两种解决办法之一来解决这一问题:
- adding a delimiter (ie
or ,
) to the front or end of your header row in the source file, or,
- removing any trailing delimiters in your data
The choice will depend on the structure of your data.
test.csv Example:
If your test.csv looks like this:
v1,v2,v3
a1,a2,a3,
b1,b2,b3,
By default, read.table
interprets this file as having one fewer header columns than the data because the delimiters don t match. This is how it is interpreted by default:
v1,v2,v3 # 3 items!! (header row)
a1,a2,a3, # 4 items
b1,b2,b3, # 4 items
第一栏(无标题)的数值为行文:<代码>a1和b1
。 如果该栏含有完全可能的重复价值,那么,你可以取得<条码>复制的行文,姓名不允许条码>错误。
如果你设定<条码>行号:姓名=FALSE条码>,则头角的变动就没有发生,但主角和数据中的栏目仍然有误。
这就是如何用<代码>行文加以解释。
v1,v2,v3 # 3 items!! (header row)
a1,a2,a3, # 4 items
b1,b2,b3, # 4 items
Solution 1
Add trailing delimiter to header row:
v1,v2,v3, # 4 items!!
a1,a2,a3, # 4 items
b1,b2,b3, # 4 items
或者,增加主角:
,v1,v2,v3 # 4 items!!
a1,a2,a3, # 4 items
b1,b2,b3, # 4 items
Solution 2
Remove excess trailing delimiter from non-header rows:
v1,v2,v3 # 3 items
a1,a2,a3 # 3 items!!
b1,b2,b3 # 3 items!!