R如何从数据框中的长列名称中删除字符 [英] R How to remove characters from long column names in a data frame
本文介绍了R如何从数据框中的长列名称中删除字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个很大的数据框,其中有很长的列名.我想通过在冒号(:)之前放置字符来缩短列名,该符号出现在数据框列的每个列名中. 寻找一种在数据帧上执行此操作的方法?
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??
推荐答案
也许(第三次尝试):
names(df) <- sub("^(.+[:])([^.]+)$", "\\2", names(df))
这篇关于R如何从数据框中的长列名称中删除字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文