I have the following data frame.
V1 <- c(2, 2, 2)
V2 <- c(12, 13, 24)
V3 <- c(3, 3, 3)
V4 <- c(1, 23, 33)
data <- data.frame(V1, V2, V3, V4)
data
V1 V2 V3 V4
1 2 12 3 1
2 2 13 3 23
3 2 24 3 33
I want to rename the V1 based on the value in V1. That means, I want rename the variable V2 as Var_2 where the number 2 comes from the V1.
Var_2 Var_3
1 12 1
2 13 23
3 24 33
Any easy way to do that? I want to replicate the process for 500 variables. Is there any way avoiding loops?