【发布时间】:2019-10-25 12:28:24
【问题描述】:
我有一些看起来像这样的数据:
country agdp apop
1 US 100 100
2 Australia 50 50
变量名是agdp 和apop,但我希望它们是gdp 和pop。我的真实数据有很多很多变量都需要这种转换。
这就是我想要的结果:
country gdp pop
1 US 100 100
2 Australia 50 50
下面的可重现代码:
df <- data.frame(stringsAsFactors=FALSE,
country = c("US", "Australia"),
agdp = c(100, 50),
apop = c(100, 50)
desired_df <- data.frame(stringsAsFactors=FALSE,
country = c("US", "Australia"),
gdp = c(100, 50),
pop = c(100, 50)
【问题讨论】: