按行值对行进行动态分组

时间:2022-12-04 07:37:28

I am looking for a way to group rows by linking the values of the cells (see link for image). For example, Row 1 is linked to row 2 by the letter "B", and row 2 is linked to row "3" by the letter C -- making those three rows group 1. Whereas, row 4 has no links and is considered group 2.

我正在寻找一种通过链接单元格的值来分组行的方法(参见图像链接)。例如,第1行通过字母“B”链接到第2行,第2行通过字母C链接到第“3”行 - 使这三行成为第1组。而第4行没有链接,被认为是第2组。

Example image

UPDATE: When I say 'linked' I mean that rows can be grouped by a common value in a cell. Given my first example, the letter "B" is present in both row 1 and row 2, which I then consider 'linked'. See the next link for a sub-sample of my original, but more complex, data.

更新:当我说'链接'时,我的意思是行可以按单元格中的公共值进行分组。鉴于我的第一个例子,字母“B”出现在第1行和第2行,然后我将其视为“链接”。请参阅下一个链接,查看原始但更复杂的数据的子样本。

Sub-sample of original data

原始数据的子样本

I apologize in advance if this question has been addressed in an earlier post but I simply don't know how to phrase it.

如果这个问题已经在之前的帖子中得到解决,我会提前道歉,但我根本不知道该怎么说。

2 个解决方案

#1


0  

A simple solution (if I understand your problem) - Assuming you have data in columns A and B, and group numbers in C.

一个简单的解决方案(如果我理解你的问题) - 假设你有A列和B列中的数据,以及C中的组号。

Put the number 1 in the first row, "group" column (cell C1). Then put the following formula in cell C2, and drag down:

将数字1放在第一行“group”列(单元格C1)中。然后将以下公式放在单元格C2中,然后向下拖动:

=IF(B1 = A2, C1, C1 + 1)

when the cells match, the group number is the same, otherwise it increments. Simple sample:

当单元格匹配时,组编号相同,否则递增。简单样本:

按行值对行进行动态分组

Formula view of the same thing:

公式视图同样的事情:

按行值对行进行动态分组

#2


0  

Managed to find a way of solving this problem using R and the RBGL package. Really appreciate everyone's input. See link...

管理以找到使用R和RBGL包解决此问题的方法。真的很感谢大家的意见。见链接......

identify groups of linked episodes which chain together

识别连接在一起的链接剧集组

#1


0  

A simple solution (if I understand your problem) - Assuming you have data in columns A and B, and group numbers in C.

一个简单的解决方案(如果我理解你的问题) - 假设你有A列和B列中的数据,以及C中的组号。

Put the number 1 in the first row, "group" column (cell C1). Then put the following formula in cell C2, and drag down:

将数字1放在第一行“group”列(单元格C1)中。然后将以下公式放在单元格C2中,然后向下拖动:

=IF(B1 = A2, C1, C1 + 1)

when the cells match, the group number is the same, otherwise it increments. Simple sample:

当单元格匹配时,组编号相同,否则递增。简单样本:

按行值对行进行动态分组

Formula view of the same thing:

公式视图同样的事情:

按行值对行进行动态分组

#2


0  

Managed to find a way of solving this problem using R and the RBGL package. Really appreciate everyone's input. See link...

管理以找到使用R和RBGL包解决此问题的方法。真的很感谢大家的意见。见链接......

identify groups of linked episodes which chain together

识别连接在一起的链接剧集组