"X" added to all column names of my dataframe when imported into R. Why? How to keep them intact?

Hi community!!!
I have imported a .tsv file whose column names are like 713B076_profile 713B073_profile 713B065_profile 713B063_profile.
When I import that file into R, I am seeing all of the column names has been chnaged like:
X713B076_profile X713B073_profile X713B065_profile X713B063_profile. An "X" has been added at the start of each column name.
Can anyone please tell me how can I avoid the change of the names and keep all the names intact?

Thanks,
DC7

Try using readr::read_tsv(file = "your_file_path")

1 Like

It looks like @mhakanda's answer works. I suspect the reason that this is happening for you is that your column names begin with a number, which isn't a valid name in R, so an X is added to make it valid. More info here: https://stackoverflow.com/questions/10441437/why-am-i-getting-x-in-my-column-names-when-reading-a-data-frame

1 Like

Thanks @mhakanda. It works. I am getting the following message while running with read_tsv :

> otumat <- as.data.frame(read_tsv("otutable.tsv"))

── Column specification ─────────────────────────────────────────────────────────────────────────────────────────────────────
cols(
  .default = col_double()
)
ℹ Use `spec()` for the full column specifications.

What does this actually mean? Should I be concerned about it? or, this is just a friendly message?

Thanks,
DC7

One of the parameter in read_tsv is col_types. As you do not mention anything, it best guesses (smart way), which is "double" i.e. column is read as double type. You can get the same information by typing spec(otumat). But, you want to read your column otherwise say, as character, you can do that with col_types. With this message, nothing to concern about.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.