将三份重复拆分为重复份 [英] Splitting triplicates into duplicates
本文介绍了将三份重复拆分为重复份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将一式三份的结果集分成三个可能的重复项。
I am wanting to split sets of triplicate results into the three possible duplicates.
如果初始集合为
A B C
1 122 106 114
2 110 122 110
我想将其转换为
A B
1 122 106
2 122 114
3 106 114
4 110 122
5 110 110
6 122 110
combin函数将逐行完成此操作,但我无法弄清楚如何将其应用于整个数据帧(这可能会很大,我仅使用两行进行演示。)。
The combn function will do it line by line but I cannot figure out how to apply it across the full dataframe (which can be quite large, I only used two lines for demonstration purposes.).
推荐答案
您可以执行以下操作:
- 使用
lapply()
对数据的每一行应用您的combn
- 使用
rbind
合并结果 - 利用
do.call的魔力
组合由步骤1和2创建的列表。
- Use
lapply()
to apply yourcombn
for each row of the data - Use
rbind
to combine the results - Make use of the magic of
do.call
to combine the list created by steps 1 and 2.
在一行代码:
do.call(rbind, lapply(seq(nrow(dat)), function(i)t(combn(dat[i, ], 2))))
[,1] [,2]
[1,] 122 106
[2,] 122 114
[3,] 106 114
[4,] 110 122
[5,] 110 110
[6,] 122 110
这篇关于将三份重复拆分为重复份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文