Reputation: 29
I have two dataset and I want to add _pre to the name of every variable of the first data set and _post to the name of every variable in the second data set.
So variables in the first data set would be named like var1_pre var2_pre and variables in the second set would be named var1_post var2_post...
Thanks.
Upvotes: 0
Views: 82
Reputation: 5254
You can access the names of a data frame with names()
. With paste
(or paste0
in this case) you can concatenate the names and "_pre" / "_post".
df <- data.frame(a = 1:10, b = 10:1)
names(df) <- paste0(names(df), "_pre")
Upvotes: 1