R How to remove characters from long column names in a data frame

人走茶凉 提交于 2019-12-13 15:22:08

问题


I have a large dataframe with long column names in it. I would like to shorten the columnnames by dropping characters before a colon sign (:), the sign is present in every column name in the dataframe columns. Looking for a way to perform this on a dataframe??


回答1:


Perhaps (third try):

names(df) <- sub("^(.+[:])([^.]+)$", "\\2", names(df))


来源:https://stackoverflow.com/questions/26807430/r-how-to-remove-characters-from-long-column-names-in-a-data-frame

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