在R中运行简单的'rename'功能时出现错误信息 [英] Error message when running simple 'rename' function in R

查看:106
本文介绍了在R中运行简单的'rename'功能时出现错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面我在互联网上发现的一个非常简单的数据框架示例。在我机器上的RStudio中运行此文件会出现一条错误消息:

Below a very simple data frame example I found in the internet. Running this in RStudio on my machine turns out an error message:


错误:重命名的所有参数都必须命名。

Error: All arguments to rename must be named.

重命名函数似乎很简单,但不起作用一些原因,我不知道为什么。

The rename function seems to be straight forward but doesn't work for some reasons and I can't figure out why.

library("dplyr")

d <- data.frame(alpha=1:3, beta=4:6, gamma=7:9)
d
#   alpha beta gamma
# 1     1    4     7
# 2     2    5     8
# 3     3    6     9

rename(d, c("beta"="two", "gamma"="three"))

#Error: All arguments to rename must be named.


推荐答案

Mike,你的命令是有效的,但是对于plyr图书馆。如果您在同一个脚本中加载dplyr,您将收到您提到的错误。

Mike, your command is valid but for "plyr" library. If you load the "dplyr" in the same script you will get the error that you mentioned.

因此,请尝试改为:

library("plyr")
d <- data.frame(alpha=1:3, beta=4:6, gamma=7:9)
plyr::rename(d, c("beta"="two", "gamma"="three"))

请注意, sessionInfo()有助于跟踪哪些库被加载(附加)。

Note that sessionInfo() helps to keep a track of what libraries are loaded (attached).

(@Jaap的评论后更新)

(answer updated after @Jaap 's comment)

这篇关于在R中运行简单的'rename'功能时出现错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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