0

I have a dataframe, which looks like follows:

# Example data
data <- data.frame(x1.1 = rnorm(10),
                   x2.1 = rnorm(10),
                   x3.1 = rnorm(10))

I want to change the last value ".1" of all column names to ".2". It is important to find a general solution, since I will have to perform this for several big dataframes.

# Desired output:
colnames(data)
# "x1.2" "x2.2" "x3.2"

I can do that with a complicated loop, but I am sure there must be an easier way, which I am not able to find. Thank you very much for your help!

aynber
  • 22,380
  • 8
  • 50
  • 63
Joachim Schork
  • 2,025
  • 3
  • 25
  • 48

0 Answers0