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?
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?
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"
x<-as.vector(colnames(df))
colnames(df)<-substr(x,7,11)
Where df
is your data frame.