You’d think that I should know this stuff by now, but I often find myself re-learning things about reading data into R, so I’m writing down what I just re-learned: how to read data in with row names. The thing that frustrated me this time was that my csv file had a blank (i.e. empty quotes, "") entry at the top of the first column (i.e. the column with the row names). If there was no blank entry, and the first row simply had one fewer entry, then read.csv would have found my row names easily. But since there was a blank entry, read.csv got confused and put the row names into the first column of the resulting data frame.

Here’s the tip: Add row.names = 1 to the argument list of read.csv. The reason this works is that read.csv is being told that the first column (hence the row.names equals 1) contains the row names.