导入数据 - 列数多于列名

时间:2014-11-05 17:16:38

标签: r

我正在尝试在R中导入数据,它出现错误“列数比列名更多”。我想知道是否有人可以帮我提供正确的命令。部分数据如下,您可以将其复制并保存在记事本中

name                     yr1    yr2   state               party                   bday
Joseph Carter Abbott     1868   1872   North Carolina     Republican              July 15, 1825
James Abdnor             1981   1987   South Dakota       Republican              February 13, 1923
Hazel Abel               1954   1954   Nebraska           Republican              July 10, 1888
James Abourezk           1973   1979   South Dakota       Democrat                February 24, 1931
Spencer Abraham          1995   2001   Michigan           Republican              June 12, 1952
John Adair               1805   1806   Kentucky           Democratic-Republican   January 9, 1757
Alva B. Adams            1923   1924   Colorado           Democrat                October 29, 1875
Alva B. Adams            1933   1941   Colorado           Democrat                October 29, 1875
Brock Adams              1987   1993   Washington         Democrat                January 13, 1927
John Quincy Adams        1803   1808   Massachusetts      Federalist              July 11, 1767
Robert H. Adams          1830   1830   Mississippi        Democrat                1792
Stephen Adams            1852   1857   Mississippi        Democrat                October 17, 1807
George D. Aiken          1941   1975   Vermont            Republican              August 20, 1892
James L. Alcorn          1871   1877   Mississippi        Republican              November 4, 1816
Nelson W. Aldrich        1881   1911   Rhode Island       Republican              November 6, 1841
Russell A. Alger         1902   1907   Michigan           Republican              February 27, 1836
J. Frank Allee           1903   1907   Delaware           Republican              December 2, 1857
George Allen             2001   2007   Virginia           Republican              March 8, 1952
Henry Justin Allen       1929   1930   Kansas             Republican              September 11, 1868
James Allen              1969   1978   Alabama            Democrat                December 28, 1912
John B. Allen            1889   1893   Washington         Republican              May 18, 1845

2 个答案:

答案 0 :(得分:1)

正如Ananda Mahto建议的那样,如果您的数据是固定宽度(似乎是在编辑之后),请使用read.fwf

答案 1 :(得分:0)

如果您使用的是CSV格式,则应指定分隔符,并确保文本数据中未使用分隔符。 例如:您的“bday”列包含“,”,因此该符号将被误解

通常明确定义 sep =“,”(或任何其他分隔符)并检查数据集不使用该符号在数据中解决问题