Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename columns by pattern in R

Tags:

r

rename

renaming

I would like to rename all my columns in a dataframe by a specific pattern.

My input:

Log.NE122  Log.NE244  Log.NE144
-0.33       0.98        1.0

My expected output:

 NE122  NE244  NE144
-0.33   0.98    1.0

Cheers.

like image 517
user3091668 Avatar asked Apr 16 '14 11:04

user3091668


1 Answers

You can use regular expressions to change the colnames() of an object. Here I'm replacing the Log. with nothing:

colnames(object) <- sub("Log\\.", "", colnames(object))
like image 60
alexwhan Avatar answered Oct 02 '22 16:10

alexwhan