0

I am a beginner in r and I am currently trying to change the name of my variables. There is a column called "var" and the column has two variables: Índice de volume de vendas no comércio varejista and Índice de receita nominal de vendas no comércio varejista, respectively. I would like to rename the first variable to "volume" and the second one to "receita". In order to do this I already tried to use the rename function, but it is not working. I already tried the following code:

rename(pmc_rvar, volume = Índice de volume de vendas no comércio varejista (Número-índice))

The following answer appears: Erro: unexpected symbol in "rename(pmc_rvar, volume = Índice de"

zork1
  • 69
  • 5
  • 3
    Try to enclose names with special characters and spaces in backticks. – Parfait Jan 25 '22 at 16:30
  • Likely a duplicate of [Changing column names of a data frame](https://stackoverflow.com/q/6081439/8366499) – divibisan Jan 25 '22 at 16:31
  • 1
    ```dplyr::rename(pmc_rvar, volume = `Índice de volume de vendas no comércio varejista`)``` should work – Ane Jan 25 '22 at 16:31
  • Does this answer your question? [Changing column names of a data frame](https://stackoverflow.com/questions/6081439/changing-column-names-of-a-data-frame) – Claudiu Papasteri Jan 25 '22 at 16:32
  • ```dplyr::rename(iris, `Sepal L e n g t h` = Sepal.Length)```. The name with the spaces needs backticks, the old name doesn't. – Rui Barradas Jan 25 '22 at 16:33

1 Answers1

1

As you have got blank spaces, you need to either put the whole column name into backticks, or you need to remove or fill the blank spaces.

Try this:

library(dplyr)
   
pmc_rvar <- rename(pmc_rvar, volume = `Índice de volume de vendas no comércio varejista
    (Número-índice)`)
Jose
  • 421
  • 3
  • 10
Leonhard Geisler
  • 506
  • 3
  • 15