The name of columns

Dear Friends,
In my data the columns have a number in their name, so the name of column changes after import dataset.

How can I solve this problem?

I want the real name of the column "1 set, 2 set, ..."

Thanks for your help!

In R, a variable cannot start with a number, so you will have to find an alternative.

> x <- 2
> 2x <- 4
Error: unexpected symbol in "2x"

You do not say what function you are using to read in your data. The functions read.table and read.csv have a argument called check.names which is TRUE by default and causes syntactically invalid names to be modified. If you set that to FALSE, I believe the names will not be changed. However, as mentioned by others, using such names is a pain.

You could skip the column names on import, and then set them manually afterwards - quite easy if they have a simple, repetitive structure:

names(my_data) <- c(paste0("set_", c(1:20)))


True, but not advisable as it is quite prone to cause down stream issues :slightly_smiling_face:

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

you can use such names but it makes life a bit of a pain generally., and is best avoided for an easy life. You have to use backticks to reference them (unless you are using certain functions that can accept names in regular quotes.

x <- 2
`2x` <- 4