R语言 如何修复:Error in select unused arguments
在这篇文章中,我们将着眼于修复R编程语言中选择未使用参数的错误的方法。
选择未使用参数 的错误:当程序员试图在R中使用dplyr包的select()函数时,R编译器会产生这个错误,前提是加载了MASS包。当这种错误发生时,R会尝试使用MASS包中的select()函数来代替。本文主要介绍如何解决这个错误。
错误。select(., cyl, mpg)中的错误:未使用的参数( cyl, mpg)
当错误可能发生时
考虑一下下面的R程序。
例子
# R program to demonstrate when the
# error might occur
# Importing libraries
library(dplyr)
library(MASS)
# Determine the average mpg grouped by 'cyl'
mtcars %>% select(cyl, mpg) %>% group_by(cyl) %>% summarize(avg_mpg = mean(mpg))
输出
解释: 编译器产生这个错误是因为MASS包的select()函数和dplyr包的select()函数之间有冲突。
如何修复该错误
这个错误可以通过直接使用dplyr包中的select()函数来消除。
例子
# R program to demonstrate how to
# fix the error
# Importing libraries
library(dplyr)
library(MASS)
# Determine the average mpg grouped by 'cyl'
mtcars %>%
dplyr::select(cyl, mpg) %>%
group_by(cyl) %>%
summarize(avg_mpg = mean(mpg))
输出
解释: 代码编译成功,没有任何错误,因为dplyr明确使用了dplyr包而不是MASS包中的select()函数。