如何将多个数据框中的单个列重命名为R所在的数据框的名称?

问题描述 投票:0回答:1

我目前正在尝试重命名多个数据框中的单个列以匹配R中的数据框名称。

我在网站上看到了一些问题/解决方案,它们与我尝试执行的操作类似,但似乎没有一个动态地执行此操作。我有45个以上的数据框,需要在其中重命名一列,因此可以手动输入每个单独的名称,但很耗时。

Dataframe1 <- column
Dataframe2 <- column
Dataframe3 <- column


I want it to look like this:
Dataframe1 <- Dataframe1
Dataframe2 <- Dataframe2
Dataframe3 <- Dataframe3


The ultimate goal is to have a master dataframe with columns Dataframe1, Dataframe2, and Dataframe3
r dataframe naming
1个回答
0
投票

我们可以将所有数据集放入list并在list中立即重命名

lst1 <- lapply(mget(ls(pattern = "Dataframe\\d+")), function(x) {
             names(x)[5] <- "newcol"
             x})
© www.soinside.com 2019 - 2024. All rights reserved.