如标题所述,我尝试使用gsub,其中将向量用于“模式”和“替换”。当前,我有一个类似于以下代码: names(x1) <- gsub("2110027599", "Inv1", names(x1)) #x1 is a data frame names(x1) <- gsub("2110025622", "Inv2", names(x1)) names(x1) <- gsub("2110028045", "Inv3", names(x1)) names(x1) <- gsub("2110034716", "Inv4", names(x1)) names(x1) <- gsub("2110069349", "Inv5", names(x1)) names(x1) <- gsub("2110023264", "Inv6", names(x1))我希望做的是这样的: a <- c("2110027599","2110025622","2110028045","2110034716", "2110069349", "2110023264") b <- c("Inv1","Inv2","Inv3","Inv4","Inv5","Inv6") names(x1) <- gsub(a,b,names(x1))我猜想某个地方有一个Apply函数可以做到这一点,但我不确定要使用哪个函数!
3 回答
- 3 回答
- 0 关注
- 794 浏览
添加回答
举报
0/150
提交
取消