-3

All my column names start with

A.ABC.test1
A.ABC.test2
A.ABC.test3
A.ABC.test4
A.ABC.test5

I would like to keep only test1 , test2 ...

Any ideas?

3 Answers3

2

simply do: (by chance the same as @jogo commented)

colNames <- c("A.ABC.test1","A.ABC.test2","A.ABC.test3","A.ABC.test4","A.ABC.test5")
sub(".*\\.","",colNames)

#[1] "test1" "test2" "test3" "test4" "test5"
Andre Elrico
  • 8,959
  • 1
  • 37
  • 61
0

Maybe just gsub("A.ABC.", "", x)

Lennyy
  • 4,953
  • 2
  • 7
  • 21
0
x<-as.vector(colnames(df))
colnames(df)<-substr(x,7,11)

Where df is your data frame.

rar
  • 771
  • 1
  • 7
  • 22