0

I am trying to rename the column "P3Q03.1." to "P2Q03.1." in one of my dataframes. However, the name remains unchanged. Here is what I do:

colnames(df[colnames(df)=="P3Q03.1."])<-"P2Q03.1."

Here is what results:

 > df$P3Q03.1. [1] Mein Mein Levels: leer Mein > df$P2Q03.1. NULL > colnames(df[colnames(df)=="P3Q03.1."])<-"P2Q03.1." > df$P3Q03.1. [1] Mein Mein Levels: leer Mein > df$P2Q03.1. NULL 

Both before and after the renaming attempt, trying to display column "P3Q01.1." works and displaying "P2Q01.1." does not. It is as if my renaming attempt does not do anything, but it also does not create an error message.

2
  • You can use dplyr. df %>% rename(P2Q03.1 = P3Q03.1) Commented Feb 6, 2019 at 11:11
  • 1
    The solution for me was: names(df)[names(df) == 'P3Q03.1.'] <- 'P2Q03.1.' Commented Feb 6, 2019 at 11:18

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.