从只有一个值不同的行对中获取唯一行(观察)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从只有一个值不同的行对中获取唯一行(观察)相关的知识,希望对你有一定的参考价值。
我有一个data.table,它有许多行,q.val的值不同。对于这些对中的每一对,我想选择具有较小值的行。换句话说,我想从DT1到DT2(见下文)。在data.table
包或其他方面有一个简单的方法吗?
DT1
cluster q.val
c1 8.68E-03
c1 1.00E+00
c2 4.53E-05
c2 1.00E+00
c3 2.46E-03
c3 1.00E+00
c4 4.18E-05
c4 1.00E+00
c5 1.00E+00
c5 3.98E-05
c6 1.00E+00
c6 4.71E-06
DT2
cluster q.val
c1 8.68E-03
c2 4.53E-05
c3 2.46E-03
c4 4.18E-05
c5 3.98E-05
c6 4.71E-06
鉴于我通过原始问题编辑的答案,以发布我的真实表格的一部分
cluster pathway q.val
c1 Adrenergic signaling in cardiomyocytes -3.01E-06
c1 Adrenergic signaling in cardiomyocytes -1.80E+00
c2 Adrenergic signaling in cardiomyocytes -5.07E-06
c2 Adrenergic signaling in cardiomyocytes -1.30E+00
c3 Adrenergic signaling in cardiomyocytes -1.46E-06
c3 Adrenergic signaling in cardiomyocytes -2.32E+00
c4 Adrenergic signaling in cardiomyocytes -1.60E-05
c4 Adrenergic signaling in cardiomyocytes -1.75E+00
c5 Adrenergic signaling in cardiomyocytes 2.58E+00
c5 Adrenergic signaling in cardiomyocytes 2.53E-06
c6 Adrenergic signaling in cardiomyocytes 3.54E+00
c6 Adrenergic signaling in cardiomyocytes 8.74E-08
c7 Adrenergic signaling in cardiomyocytes -4.85E-02
c7 Adrenergic signaling in cardiomyocytes -3.98E-03
c8 Adrenergic signaling in cardiomyocytes 9.73E-01
c8 Adrenergic signaling in cardiomyocytes 3.44E-05
c1 Aldosterone synthesis and secretion -3.01E-06
c1 Aldosterone synthesis and secretion -1.64E+00
c2 Aldosterone synthesis and secretion -5.07E-06
c2 Aldosterone synthesis and secretion -1.49E+00
c3 Aldosterone synthesis and secretion -1.46E-06
c3 Aldosterone synthesis and secretion -1.85E+00
c4 Aldosterone synthesis and secretion -1.60E-05
c4 Aldosterone synthesis and secretion -1.40E+00
c5 Aldosterone synthesis and secretion 2.58E+00
c5 Aldosterone synthesis and secretion 2.53E-06
c6 Aldosterone synthesis and secretion 3.45E+00
c6 Aldosterone synthesis and secretion 8.74E-08
c7 Aldosterone synthesis and secretion -1.28E-02
c7 Aldosterone synthesis and secretion -1.42E-02
c8 Aldosterone synthesis and secretion 4.24E-01
c8 Aldosterone synthesis and secretion 3.44E-05
答案
DT1[, min(q.val), by = c("cluster", "pathway")]
data.table中的基本语法允许您使用“by”语句来区分应用函数(在本例中为“min”)的位置。值得注意的是,只有每个群集没有多个不同的路径时,这才有效。如果有,则每个群集将有多个行。
以上是关于从只有一个值不同的行对中获取唯一行(观察)的主要内容,如果未能解决你的问题,请参考以下文章