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

如何统计或标识组内leader与成员是否存在历史交互及累计次数

累计统计群组leader与成员历史交互次数需求

问题描述

我查阅了大量计数、配对相关的问题,但未找到该问题的解决方案。
我的数据包含跨时间的数千个群组,每个群组的agent构成各不相同,通过leader_dummy虚拟变量标识群组的一位或多位leader,不少agent会多次担任leader。我需要生成一个虚拟变量,标识leader与组内其他agent是否存在历史交互,理想情况下可累计统计交互次数,但由于样本中agent、群组、数据行数量极大,我暂未找到可行的实现方案。
为说明问题,以群组1672为例,我希望统计或记录leader(agent_id 6031)与组内其他成员的所有关系,当后续样本中该关系再次出现时,可在新列中统计相关次数,以下是示例数据:

structure(list(year = c(1987L, 1987L, 1987L, 1987L, 1987L, 1987L, 
1987L, 1989L, 1989L, 1989L, 1989L, 1989L, 1989L, 1989L, 1989L, 
1989L, 1989L, 1989L, 1989L, 1989L, 1989L, 1989L, 1989L, 1989L, 
1989L, 1989L, 1989L, 1989L, 1989L, 1989L, 1989L, 1990L, 1990L, 
1990L, 1990L, 1990L, 1990L, 1990L, 1990L, 1990L, 1990L, 1990L
), group_id = c(1672L, 1672L, 1672L, 1672L, 1672L, 1672L, 1672L, 
5838L, 5838L, 5838L, 5838L, 5838L, 5838L, 5838L, 5838L, 5838L, 
5838L, 5838L, 5838L, 5838L, 5838L, 5838L, 5838L, 5838L, 5838L, 
5838L, 5838L, 5838L, 5838L, 6143L, 6143L, 7044L, 7044L, 7044L, 
7044L, 7044L, 7044L, 7044L, 7044L, 7044L, 7044L, 7044L), agent_id = c(7836L, 
7878L, 5855L, 8864L, 8857L, 7910L, 6031L, 5846L, 7878L, 5891L, 
7838L, 7828L, 8926L, 5919L, 5925L, 5933L, 8857L, 5978L, 8834L, 
7888L, 8903L, 6014L, 8859L, 6059L, 7845L, 2446L, 6127L, 8902L, 
5893L, 8995L, 8836L, 7836L, 7878L, 6309L, 7828L, 6138L, 5952L, 
7844L, 7845L, 6084L, 7910L, 6532L), leader_dummy = c(0, 0, 0, 
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)), row.names = c(NA, 
-42L), class = c("tbl_df", "tbl", "data.frame"))

样例数据预览:

# A tibble: 20 x 4
    year group_id agent_id leader_dummy
   <int>    <int>    <int>        <dbl>
 1  1987     1672     7836            0
 2  1987     1672     7878            0
 3  1987     1672     5855            0
 4  1987     1672     8864            0
 5  1987     1672     8857            0
 6  1987     1672     7910            0
 7  1987     1672     6031            1
 8  1989     5838     5846            0
 9  1989     5838     7878            0
10  1989     5838     5891            0
11  1989     5838     7838            0
12  1989     5838     7828            0
13  1989     5838     8926            0
14  1989     5838     5919            0
15  1989     5838     5925            0
16  1989     5838     5933            0
17  1989     5838     8857            0
18  1989     5838     5978            0
19  1989     5838     8834            0
20  1989     5838     7888            0

期望输出

以下是期望的输出效果(仅对原有数据做了编辑以展示需求):

year group_id agent_id leader_dummy   prior_interactions
1987     1672     7836            0   0
1987     1672     7878            0   0 
1987     1672     5855            0   0
1987     1672     8864            0   0
1987     1672     8857            0   0
1987     1672     7910            0   0
1987     1672     6031            1   0     
 .
 . 
 .
1990     2549     5846            0   0
1990     2549     7878            1   0 
1990     2549     5891            0   0
1990     2549     6031            0   1   #was in the same group (1672) with leader  
1990     2549     7828            0   0
1990     2549     8926            0   0
1990     2549     5855            0   0
 .
 .
 .
1991     8785     7878            0   1   #was in the same group (1672) with leader
1991     8785     1065            0   0
1991     8785     7910            0   1   #was in the same group (1672) with leader
1991     8785     2084            0   0
1991     8785     6031            1   0
 . 
 .
 .
1993     9526     8926            1   0
1993     9526     7878            0   1   #was in the same group (2549) with leader
1993     9526     2888            0   0
1993     9526     1003            0   0
 .
 .
 .
1994     10260    7878            1   0
1994     10260    1065            0   1   #was in the same group (8785) with leader
1994     10260    8926            0   1   #was in the same group (9526) with leader
1994     10260    6031            0   1   #was in the same group (1672, 2549, 8785)  with leader   
1994     10260    1533            1   0
 .
 .
 .
1995     11044    7860            0   0
1995     11044    1533            1   0
1995     11044    7828            0   0
1995     11044    6138            0   0
1995     11044    1065            0   1   #was in the same group (10260) with leader
1995     11044    7844            0   0
1995     11044    8926            0   1   #was in the same group (10260) with leader
1995     11044    6084            0   0
1995     11044    7878            0   1   #was in the same group (10260) with leader

补充说明

  • 群组可能存在多位leader的情况,会导致组内交互数量进一步提升,也增加了问题复杂度。

澄清说明

此前的示例对需求的表述不够清晰,希望上述修改可以说明需求,如果仍有疑问可告知我补充示例。
本质上我的数据中agent之间存在大量重复交互,随着关系形成会有越来越多的协作,我希望以此衡量网络的形成过程,如果可以统计这些交互随时间的累计次数会更好,但我认为实现难度较高。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.07 05:00:02