【问题标题】:Unused argument error when creating a Tibble table创建 Tibble 表时出现未使用的参数错误
【发布时间】:2020-02-25 16:03:38
【问题描述】:

我正在处理这些数据:

library("RCurl")
library("plm")
library("tibble")
library("dplyr")
library("car")
library("AER")
library("arm")
library("broom")

x <- getURL("https://raw.githubusercontent.com/dothemathonthatone/maps/master/main_merge1.csv")
maindf <- read.csv(text = x)

我正在尝试做一些非常简单的事情:

data <- maindf %>% as_tibble() %>% select(reg_schl, year, age_group, fee_monthly, daily_hours, fee_per_inc, deubthrt_total) %>% print()

我收到以下错误:

Error in select(., reg_schl, year, age_group, fee_monthly, daily_hours, : unused arguments (reg_schl, year, age_group, fee_monthly, daily_hours, fee_per_inc, deubthrt_total)
Traceback:

1. maindf %>% as_tibble() %>% select(reg_schl, year, age_group, 
 .     fee_monthly, daily_hours, fee_per_inc, deubthrt_total) %>% 
 .     print()
2. withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
3. eval(quote(`_fseq`(`_lhs`)), env, env)
4. eval(quote(`_fseq`(`_lhs`)), env, env)
5. `_fseq`(`_lhs`)
6. freduce(value, `_function_list`)
7. function_list[[i]](value)

所以我使用 R 数据尝试了相同的代码:

data(Fatalities, package = "AER")
road <- Fatalities %>%
as_tibble() %>%
select(state, year, beertax, fatal, pop) %>%
print()

我也遇到了同样的错误。

【问题讨论】:

    标签: r tibble


    【解决方案1】:

    当您加载 library(ARM) 时,您应该会看到以下消息:

    正在加载所需的包:MASS

    附加包:'MASS'

    以下对象被“package:dplyr”屏蔽:

    select
    

    这意味着当您调用select 时,您使用的是MASS::select 而不是dplyr::select

    相反,您可以显式运行:

    maindf %>% as_tibble() %>% 
      dplyr::select(reg_schl, year, age_group, fee_monthly, daily_hours, 
                    fee_per_inc, deubthrt_total) 
    
    

    MASS::selectdplyr::select 之间的冲突非常常见。您还可以使用select &lt;- dplyr::select 重新定义选择以使用dplyr::select 以节省一些输入。

    【讨论】:

    • 最后一句不应该用select &lt;- dplyr::select吗?
    • @Chris 感谢您回答这个问题。我会迷路一段时间试图弄清楚。
    猜你喜欢
    • 2021-10-20
    • 2022-08-19
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 2014-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多