首页 > 解决方案 > 使用 group_by 时不支持的类型

问题描述

尝试编织降价时遇到问题。当我运行以下代码时:

matchlist <- data.frame(LIST) %>%
             group_by(school) %>%
             filter(match_score == min(match_score))

我收到以下错误:

grouped_df_impl(data, unname(vars), drop) 中的错误:列testscore的类型不受支持 NULL 调用:... group_by.data.frame -> grouped_df -> grouped_df_impl -> .Call

“testscore”是数据框 LIST 中的另一列,当我只运行这个块时,不会发生这个错误。我注意到的另一件事是,当我运行上面的代码时,我在匹配列表上附加了一堆“attr”,并且匹配列表的类是

> class(matchlist)
  [1] "grouped_df" "tbl_df"     "tbl"        "data.frame"

而不仅仅是“data.frame”。

“LIST”的简化结构为:

code    school    testscore    match_score
   1       aaa          aaa              0
   1       aaa          aba          0.211
   1       aaa          bba          0.544
   2       bbb          bvv          0.888
   2       bbb          bbd          0.015
   3       ccc          sss          0.899
   ...     ...          ...            ...

我使用testscore为每个学校配对并进行了模糊匹配(匹配分数是最后一列)。我正在尝试为每所学校选择最好的分数(最低),所以我按学校名称对它们进行分组并尝试制作匹配列表。

如果您能帮我解决这个问题,我将不胜感激。


这是 dput 结果。

> dput(droplevels(head(LIST, 4)))
structure(list(code = c(102, 102, 102, 104), school = c("UNIVERSITY OF AAA", 
"UNIVERSITY OF AAA", "UNIVERSITY OF AAA", 
"BBB COLLEGE"), testscore = c("UNIVERSITY OF AAA", 
"UNIVERSITY OF SOUTH AAA", "AAA COLLEGE", 
"UNIVERSITY OF AAA SCHOOL"), match_score = c(0.0797101449275361, 
0.194990021076978, 0.366802437561176, 0.46046176046176)), .Names = c("code", 
"school", "testscore", "match_score"), row.names = c(NA, 4L), class = 
"data.frame")

标签: rgroup-bydplyrknitrattr

解决方案


推荐阅读