I am trying to read in a file that has 24 column headers, but 14 additional null values. See link: https://www.elections.il.gov/ElectionInformation/CandDataFile.aspx?id=51
Whenever I run the code below, I get the message
"more columns than column names."
I feel like the answer is probably simple. Any idea?
candidates <- read.csv(file = "candidates.txt", sep = ",",
header = TRUE, stringsAsFactors = FALSE)
One solution is to read the headers only with one command, the data without header in a second, and then delete excess columns and set the names.
NAMES <- read.table("candidates.txt", nrow = 1, stringsAsFactors = FALSE, sep = ",")
DATA <- read.table("candidates.txt", skip = 1, stringsAsFactors = FALSE, sep = ",")
DATA <- DATA[, 1:24]
names(DATA) <- NAMES
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With