You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R语言统计df2中各(Measures,Format)组合在df1中的缺失数量

实现代码

你可以通过先统计df1各组合的实际题量,再关联df2计算差值实现需求,完整代码如下:

library(tidyverse)

# 1. 统计df1中每个(Measures, Format)组合的实际存在题量
df1_cnt <- df1 %>% 
  count(Measures, Format, name = "actual_count")

# 2. 关联df2计算缺失量
res <- df2 %>% 
  left_join(df1_cnt, by = c("Measures", "Format")) %>% 
  # df1中完全不存在的组合默认实际数量为0
  mutate(actual_count = replace_na(actual_count, 0),
         # 缺失量 = 需求数 - 实际数,若实际数超过需求则缺失量为0
         missing_count = pmax(Number - actual_count, 0))

输出示例

基于你提供的示例数据,运行后得到的res结果如下:

MeasuresFormatNumberactual_countmissing_count
space and shapeConstructed Response Expert40931
space and shapeConstructed Response Manual110
space and shapeSimple Multiple Choice22616
space and shapeConstructed Response Auto-coded110
asdafasfas000

完全符合你举例的需求:space and shape + Constructed Response Expert组合缺失31道题。


内容的提问来源于stack exchange,提问作者ujjwal tyagi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 19:45:06