如何将字符串附加到 R 中的变量名称子集? [英] How to append a string to subset of variable names in R?

查看:24
本文介绍了如何将字符串附加到 R 中的变量名称子集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改数据框中选定的几个变量名称.如何在不键入每个旧名称和每个新名称的情况下执行此操作?我认为下面的代码可能有效,但没有.我正在尝试将Econ"附加到数据框中标识的每个现有名称.

I am trying to alter a select few of my variable names in a data frame. How can I do this without typing each of the old names and each of the new names? I thought the code below might work but it hasn't. I am trying to append "Econ" to each of the existing names identified in the data frame.

    names(wb.misc)[3,13,14,20,22,47,61,62,64,68,73] <- 
         paste("Econ", names(wb.misc)[3,13,14,20,22,47,61,62,64,68,73], sep = "-")

推荐答案

你需要把 c() 放在索引周围

You need to put c() around the indices

 names(wb.misc)[c(3,13,14,20,22,47,61,62,64,68,73)] = paste("Econ", names(wb.misc)[c(3,13,14,20,22,47,61,62,64,68,73)], sep = "-")

这篇关于如何将字符串附加到 R 中的变量名称子集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆