Rename columns by pattern in R

試著忘記壹切 提交于 2019-11-30 05:57:11

问题


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.


回答1:


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))


来源:https://stackoverflow.com/questions/23108808/rename-columns-by-pattern-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!