2019-02-28
阅读量:
2104
如何替换R中的列名
如何替换r中的列名,例如列A,B,C,D,我希望将所有列更改为A_id,B_id,C_id,D_id,因此所有列名称的末尾都将包含“_id”。
使用str_replace_all我们可以找到特定的字符串并替换,但我不知道如何在最后更改
df %>% str_replace_all( '_', '_id')
解决办法:你可以使用names或colnames像这样的函数:
names(df) <- paste0(names(df), "_id")
或者你可以结合使用它gsub来只替换特定的东西,例如,如果你想要替换iris数据集中的任何名称来使用空间而不是完全停止,你可以写:
df <- head(iris)
names(df) <- gsub("[.]", " ", names(df))






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
1条评论