More Columns Than Column Names Error

I've been trying to load a .txt file using the command line
exp_counts <- read.table(file="mouse_mammary_counts2.txt", sep = "\t", header = T, row.names=1)
However, I keep receiving an error that there are more columns than column names.

The formatting is a little off because I had to convert to PDF and upload to Docs, but the data set is here:

I am completely new to using RStudio and this has been driving me up the wall, I greatly appreciate any help. It seems like there should be a simple solution but I just haven't been able to figure it out.

I see, at most, 11 column names and 13 data columns, so the error seems genuine. I say "at most" because one pair of column names seems run together but that may just be a problem with the conversion to PDF. Except for the first column name, they seem to have a sequential prefix of GSM1480291, GSM1480292, etc but I do not see the two GSM1480298 and GSM1480299. Should those be present?

1 Like

The two column names running together is a conversion issue. This is for a data set provided for a class exercise so I do not believe the absence of GSM1480298 and GSM1480299 is an error.

I noticed that mismatch and tried to add two additional column headers but still received the same error message, so I'm not sure if there is another problem as well.

I think this will work, though leaving you without the expected column names

exp_counts <- read.table(file="mouse_mammary_counts2.txt", sep = "\t", header = FALSE, row.names=1, skip = 1)

Or this will bring in the first column as a normal column and not as row names.

exp_counts <- read.table(file="mouse_mammary_counts2.txt", sep = "\t", header = FALSE, skip = 1)

The column names can be assigned afterwards with the colnames() function.