与R中的标题中的“关键字”相加

时间:2016-02-14 03:28:11

标签: r dataframe

enter image description here

我的数据集在data.frame中有数百列数据,每列的标题名称是城市名称+其州的缩写。我不确定城市名称和州名称之间的“分隔符号”是什么,我想删除所有城市的名称以获得新的data.frame。 喜欢: enter image description here

我试过这种方式,但它不起作用,似乎这些单词没有用“..”分隔。

Header = c(colnames(CityValue))
split_fun = function(str){
    strsplit(str,"..")[[1]][1]
}
sapply(Header, split_fun)

我得到了:

enter image description here

0 个答案:

没有答案