我有:
> dput(for_stack)
structure(list(id = c("20230420-01", "20230420-02", "2023042110-01",
"2023042110-02", "2023042112-01", "2023042112-02", "2023042114-01",
"2023042114-02", "2023042214-01", "2023042214-02"), pair_id = c(20230420L,
20230420L, 2023042110L, 2023042110L, 2023042112L, 2023042112L,
2023042114L, 2023042114L, 2023042214L, 2023042214L), mean_blast = c(3.82352941176471,
4.46153846153846, 1.71428571428571, 1.0625, 4.8125, 4, 3.5, 1.25,
4.9375, 4.5)), row.names = c(NA, 10L), class = "data.frame")
字符串
每个pair_id
有两行,我想知道每对中哪一行包含更高的mean_blast
值,使得:
> dput(for_stack)
structure(list(id = c("20230420-01", "20230420-02", "2023042110-01",
"2023042110-02", "2023042112-01", "2023042112-02", "2023042114-01",
"2023042114-02", "2023042214-01", "2023042214-02"), pair_id = c(20230420L,
20230420L, 2023042110L, 2023042110L, 2023042112L, 2023042112L,
2023042114L, 2023042114L, 2023042214L, 2023042214L), mean_blast = c(3.82352941176471,
4.46153846153846, 1.71428571428571, 1.0625, 4.8125, 4, 3.5, 1.25,
4.9375, 4.5), higher = c(FALSE, TRUE, TRUE, FALSE, TRUE, FALSE,
TRUE, FALSE, TRUE, FALSE)), row.names = c(NA, 10L), class = "data.frame")
id pair_id mean_blast higher
1 20230420-01 20230420 3.823529 FALSE
2 20230420-02 20230420 4.461538 TRUE
3 2023042110-01 2023042110 1.714286 TRUE
4 2023042110-02 2023042110 1.062500 FALSE
5 2023042112-01 2023042112 4.812500 TRUE
6 2023042112-02 2023042112 4.000000 FALSE
7 2023042114-01 2023042114 3.500000 TRUE
8 2023042114-02 2023042114 1.250000 FALSE
9 2023042214-01 2023042214 4.937500 TRUE
10 2023042214-02 2023042214 4.500000 FALSE
型
我相信有一种方法可以用summarize
和group_by
来实现这一点,但我还没有弄清楚。
2条答案
按热度按时间vsdwdz231#
在
dplyr
中,您可以按组使用max
:字符串
wyyhbhjk2#
在基数R中,你可以在
ave
中使用rank
,2
是更高的值。字符串
如果有平局,两者都得到
FALSE
。