I have a dataframe "data" with 50 variables. For the analysis purpose, I want to rename all these variables by adding 1 at the end of each variable . Following is the procedure that I followed (for a dataframe "datasample" of 10 variables):
names(datasample)
# original colnames for 10 variables
names(datasample)
[1] "a" "z" "y" "b" "bb" "ca" "a3"
[8] "b2" "as" "ask"
#rename 10 variables
names(datasample)<-c("a1","z1","y1","b1","bb1","ca1","a31","b21","as1","ask1")
I was wondering whether there is an efficient way of renaming these multiple variables. Thanks in advance.
names(datasample) <- paste(names(datasample), "1", sep="")
Or, equivalently,
names(datasample) <- paste0(names(datasample), "1")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With