基于r中的另一个数据帧重命名列

发布于 2025-02-12 18:46:44 字数 218 浏览 1 评论 0原文

我的列标题不正确。我想根据数据框架(第一列的名称对应我的数据框架的第一个标题),将矩阵的所有列重命名(因为我具有V1,V2,V3,..)。我必须重复39列。因此,目标是做一个循环。

DF1是必须更改的矩阵。

for (i in 1:39) {
names(df1[,i]) <- names(dfnorm[,i])
}

此代码不起作用。

My column titles are not correct. I want to rename all my column of a matrix (because i have v1,v2,v3,..) according to data frame (the name of the first column corresponds to the first title of my data frame). I have to repeat this for my 39 columns. So the goal would be to do a for-loop.

df1 is the matrix that has to be changed.

for (i in 1:39) {
names(df1[,i]) <- names(dfnorm[,i])
}

This code is not working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卖梦商人 2025-02-19 18:46:44

如果我正确理解,这应该有效:

names(df1)[1:39] <- names(dfnorm)[1:39]

If I understand correctly, this should work:

names(df1)[1:39] <- names(dfnorm)[1:39]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文