How to Fix: Error in select unused arguments in R?
In this article, we will be looking toward the approach to fix the error in selecting unused arguments in the R programming language.
Error in selecting unused arguments: The R compiler produces this error when a programmer tries to use the select() function of the dplyr package in R provided that the MASS package loaded. R tries to make use of the select() function from the MASS package instead when such an error takes place. This article focuses on how to fix this error.
Error: Error in select(., cyl, mpg) : unused arguments (cyl, mpg)
When the error might occur:
Consider the following R program.
Example:
R
library (dplyr)
library (MASS)
mtcars %>% select (cyl, mpg) %>% group_by (cyl) %>% summarize (avg_mpg = mean (mpg))
|
Output:
Interpretation: The compiler produces this error because there is a clash between the select() function from the MASS package and the select() function from the dplyr package.
How to Fix the Error:
This error can be eliminated by using the select() function directly from the dplyr package.
Example:
R
library (dplyr)
library (MASS)
mtcars %>%
dplyr:: select (cyl, mpg) %>%
group_by (cyl) %>%
summarize (avg_mpg = mean (mpg))
|
Output:
Interpretation: The code compiled successfully without any error because dplyr explicitly uses the select() function in the dplyr package rather than the MASS package.
Last Updated :
18 Mar, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...