r - 使用 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")
解决方案
推荐阅读
- css - 如何让非固定表格单元格显示省略号
- azure-cosmosdb - azure-cosmosdb DocumentDB 迁移工具错误
- python - md5 numpy 数组的快速方法
- python - 就地矩阵乘法numpy
- sql - SQLite如何获取下一行,但如果当前是最后一行,则获取第一行
- r - 使用其他列中的范围填充列
- android - 如何从另一个类调用意图?
- java - 爪哇 | PNG AVG 和 Paeth 过滤器导致压缩图像上出现线条
- angular - 基于 Html 中的类型输入
- visual-studio-code - 从 Windows 系统范围的 Visual Studio Code 迁移到用户设置的迁移过程是什么?