With the help of tidyverse: how to rename a column to a variable name

0 votes

I have taken a simple dataset "mtcars"

image

Now I want to change the column "disp" to "Displacement"

I can do easily by

colnames(mtcars)[3] = "Displacement"

But I want to use tidyverse so it can be used in a pipe?

Apr 3, 2018 in Data Analytics by DataKing99
• 8,130 points

edited Apr 3, 2018 by DataKing99 49 views

1 answer to this question.

0 votes

With the help of Dplyr: rename function we can do

rename(mtcars, !!"Displacement":=disp)

The rename is as follows rename(data, !!"New_name":="Old_name")

answered Apr 3, 2018 by DeepCoder786
• 1,720 points

edited Apr 3, 2018 by DeepCoder786

Related Questions In Data Analytics

0 votes
2 answers

How to count the number of elements with the values in a vector?

Use dplyr function group_by(). > n = as.data.frame(num) > ...READ MORE

answered Aug 21 in Data Analytics by anonymous
• 31,840 points
131 views
0 votes
1 answer

How to write a custom function which will replace all the missing values in a vector with the mean of values in R?

Consider this vector: a<-c(1,2,3,NA,4,5,NA,NA) Write the function to impute ...READ MORE

answered Jul 4, 2018 in Data Analytics by CodingByHeart77
• 3,690 points
199 views
0 votes
2 answers
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,550 points
80 views
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,550 points
203 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,550 points
124 views
0 votes
1 answer

Plotting multiple graphs on the same page in R

If you want to plot 4 graphs ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,550 points
62 views
+1 vote
1 answer

How to convert a list of vectors with various length into a Data.Frame?

We can easily use this command as.data.frame(lapply(d1, "length< ...READ MORE

answered Apr 4, 2018 in Data Analytics by DeepCoder786
• 1,720 points
131 views
0 votes
1 answer

How to spilt a column of a data frame into multiple columns

it is easily achievable by using "stringr" ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
111 views