1

Originally the rownames of my data (a csv-file) were:

1
5
33
37

However, as I read in my data using:

data <- read.table(data, sep = ",", header = TRUE)

it seems that the rownames has been transformed to:

X1
X5
X33
X37

Are there any common reasons for why this is happening? It's entirely unintentional.

histelheim
  • 4,938
  • 6
  • 33
  • 63
  • 1
    [This question](http://stackoverflow.com/questions/10441437/x-in-my-column-names-of-an-r-data-frame) may help. – Lars Kotthoff Apr 03 '14 at 20:44
  • make the question reproducible please – eddi Apr 03 '14 at 20:54
  • as I said in a comment on [this question](http://stackoverflow.com/questions/22177756/deleting-an-extra-character-in-each-row?noredirect=1#comment34854740_22177756), you could see values in a data frame that had `X` prepended if you did some sort of melting/casting where what were previously numeric values turned into **column** names and were then re-converted into data values. However, I agree with Greg Snow's answer below that you have to be doing something special in order for **row** names to be mutated in this way. – Ben Bolker Apr 03 '14 at 23:23

1 Answers1

3

Are you sure that it is the row names that are changing? not the column names?

R generally does not modify row names, it is happy with numbers (converted to character) as row names.

The standard functions for reading in data (read.table and relatives) will convert column names that are not valid names into ones that are, for integers this mean prepending the X that you describe. If you don't want this behavior (skipping this helpful feature could lead to other complications down the line) then look at the check.names argument to read.table.

If it really is the row names that are changing then we will need a reproducible example with a text file to read in and the exact command that you used to read in the file.

Greg Snow
  • 48,497
  • 6
  • 83
  • 110