I have the following tibble:
library(tidyverse)
df <- structure(list(Sepal.Length = c(5.1, 4.9, 4.7, 4.6, 5), Sepal.Width = c(3.5,
3, 3.2, 3.1, 3.6), Petal.Length = c(1.4, 1.4, 1.3, 1.5, 1.4)), .Names = c("Sepal.Length",
"Sepal.Width", "Petal.Length"), row.names = c(NA, 5L), class = c("tbl_df",
"tbl", "data.frame"))
That looks like this:
> df
# A tibble: 5 × 3
Sepal.Length Sepal.Width Petal.Length
* <dbl> <dbl> <dbl>
1 5.1 3.5 1.4
2 4.9 3.0 1.4
3 4.7 3.2 1.3
4 4.6 3.1 1.5
5 5.0 3.6 1.4
What I want to do is to replace Sepal.Length
and Petal.Length
with appended string to_app <- ".xxx"
resulting in:
Sepal.Length.xxx Sepal.Width Petal.Length.xxx
5.1 3.5 1.4
4.9 3.0 1.4
4.7 3.2 1.3
4.6 3.1 1.5
5.0 3.6 1.4
I tried this with error:
df %>% rename(paste(Sepal.Length,to_app,sep="") = Petal.Length,paste(Sepal.Width,to_app,sep="") = Petal.Length)
Error: unexpected '=' in "df %>% rename(paste(Sepal.Length,to_app,sep="") ="