Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dplyr rename error: contains unknown variables

Tags:

r

dplyr

Very simple, renaming colnames with dplyr gives me an odd error.

 library(dplyr)

 df <- data.frame(var1=c("one","two","three"),var2=c(1,2,3)) 

 df <- 
    df %>% 
    rename(var1=are.letters, var2=are.numbers)

Error: `are.letters`, `are.numbers` contains unknown variables

second try

 df <- rename(df, var1=are.letters, var2=are.numbers)

Error: `are.letters`, `are.numbers` contains unknown variables

Wondering if quoting....

df <- 
    df %>% 
    rename('var1'='are.letters', 'var2'='are.numbers')

Error: `are.letters`, `are.numbers` contains unknown variables
like image 422
Forge Avatar asked Aug 24 '17 09:08

Forge


1 Answers

Just made the same error. So, I'm converting @akrun's useful comment into an "answer."

To fix this, the new name should be on the left hand of the equal sign and the existing name should be on the right.

Like this:

df <- df %>% 
    rename(are.letters = var1, are.numbers = var2)
like image 83
D. Woods Avatar answered Oct 23 '22 16:10

D. Woods