-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
  • 10,956
  • 6
  • 50
  • 69
0

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

Lennyy
  • 5,932
  • 2
  • 10
  • 23
0
x<-as.vector(colnames(df))
colnames(df)<-substr(x,7,11)

Where df is your data frame.

rar
  • 894
  • 1
  • 9
  • 24