4

I have tried multiple variations of the rename function in dplyr. I have a data frame called from a database called alldata, and a column within the data frame named WindDirection:N. I am trying to rename it as Wind Direction. I understand creating variable names containing spaces is not a good practice, but I want it to be named as such to improve readability for a selectInput list in shiny, and even if I settle for renaming it WindDirection I am getting all of the same error messages. I have tried:

rename(alldata, Wind Direction = WindDirection:N)

which gives the error message:

Error: unexpected symbol in "rename(alldata, Wind Direction"

rename(alldata, `Wind Direction` = `WindDirection:N`)

which does not give an error message, but also does not rename the variable

rename(alldata, "Wind Direction" = "WindDirection:N")

which gives the error message:

Error: Arguments to rename must be unquoted variable names. Arguments Wind Direction are not.

I then tried the same 3 combinations of the reverse order (because I know that is how plyr works even though I do not call it to be used using the library command earlier in my code) putting the old variable first and the new variable 2nd with similar error messages.

I then tried to specify the package as I have 1 example below and tried all 6 combinations again.

dplyr::rename(alldata, `Wind Direction` = `WindDirection:N`)

to similar error messages as the first time.

I have used the following thread as an attempt to do this myself. Replacement for "rename" in dplyr

Community
  • 1
  • 1
User247365
  • 665
  • 2
  • 11
  • 27

1 Answers1

2

as agenis pointed out, my mistake was not redefining the dataframe after renaming the variable.

So where I had

dplyr::rename(alldata,Wind Direction=WindDirection:N)

I should have

alldata <- dplyr::rename(alldata,Wind Direction=WindDirection:N)

User247365
  • 665
  • 2
  • 11
  • 27