问题
I am trying to import a .csv file into R that contains employment data from the BLS. When I attempt to import the data, every column works except the first, which gives me the error:
EmpEd <- read_csv("~/Documents/Research/Global Business Research Center/Future of Education/EmploymentbyEd.csv",
col_types = cols(`Date` = col_date(format = "%B-%y"),
`LessHsPart` = col_number(),
`HsPart` = col_number(),
`SomeUgPart` = col_number(),
`UgHighPart` = col_number(),
`LessHsUp` = col_number(),
`HsUp` = col_number(),
`SomeUgUp` = col_number(),
`UGHighUp` = col_number()))
The following named parsers don't match the column names: Date
I have checked the .csv file and that is the right column name. I'm not sure what in my code is giving me the error. Does it have to do with the way I am formatting the dates themselves?
The original dataset can be downloaded here:
https://drive.google.com/file/d/0BzuJJ0j4Lyi6R1h0T0VZOUNyaEU/view?usp=sharing
回答1:
You have an invisible character before Date which does not parse in a friendly way.
You are also using an old version of readr
. Newer versions will give that as a warning rather than an error. With a newer version the file should be read in easily, but you may have trouble referring to the Date column.
Open the file in your favorite text editor. Delete the first line and rewrite it by hand. (Not copy and paste, though you should be able to copy and paste everything but 'Date'.)
Since you have dates here I would advise against ever opening this file in Excel. Notepad may work, but my suggestion would be emax or vim.
来源:https://stackoverflow.com/questions/42933931/parser-does-not-match-column-name-in-csv-file-when-importing-using-readr-packag