我有一个包含10000行和多列的数据框,并且我想为R中的每种情况计算唯一ID:
cell.id mother.id daughter1.id daughter2.id
1 0 65 66
2 0 45 46
3 0 87 88
4 0 42 43
5 0 51 52
6 0 31 32
7 0 55 56
8 0 90 91
14 0 NA NA
其中:
我要计算的是cell.id,有多少个女儿?或者每个女儿有多少个女儿来自Daughter1.id和Daughter2.id?
这可能是两个新列,例如Daughter1.id.children
和Daughter2.id.children
:
cell.id mother.id daughter1.id daughter2.id daughter1.id.children daughter2.id.children
1 52 65 66 2 2
2 40 45 46 1 0
3 66 87 88 0 0
4 2 42 43 2 1
5 45 51 52 2 2