Gabriel Sampaio
Gabriel Sampaio

Reputation: 1

importing data - more columns than column names

I'm trying to import a data in R, it's appearing an error "more columns than column names". I'd like to know if anyone could help me giving the correct command. A part of the data is below, you can copy it and save in the notepad

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

Upvotes: 0

Views: 606

Answers (2)

Yavpolnom Shoke
Yavpolnom Shoke

Reputation: 78

if you're using CSV format you should specify the delimiters and make sure that the delimiters are not used in your text data. Ex.: your "bday" column contains "," so that symbol will be misinterpreted

usually explicitly defining sep="," (or any other delimiter) and checking the dataset not to use that symbol in data solves the problem

Upvotes: 0

Jon Chung
Jon Chung

Reputation: 165

As Ananda Mahto suggested, if your data is fixed width (which it seems to be after your edit) use read.fwf.

Upvotes: 1

Related Questions