使用聚合(R)时返回唯一最大值

时间:2016-10-04 21:11:57

标签: r

使用#include <regex> #include <string> #include <iostream> using namespace std; int main() { string user_pattern(":.*"); string s("test:55:last"); regex r("^.*(" + user_pattern + ")"); smatch matches; if (regex_search(s, matches, r)) { cout<<matches[1].str(); } return 0; } 时如何让R处理断路器并且只返回UNIQUE最大值。可以任意挑选。

谢谢,

1 个答案:

答案 0 :(得分:0)

你的意思是你只想在声明“胜利者”时得到一个结果吗?您可以编写自己的函数,并在aggregate中调用它。这样的东西应该工作(没有测试,随意发布一个最小的可重复的例子,我会测试它):

winner <- function( x ) {
    if( max( x ) > min( x ) ) {
        return( max( x ) )
    } else {
        return( NA )
    }
}

aggregate( ..., FUN = winner )