根据Scott Meyers的说法,在他的Effective STL书中 - 第46项.他声称这std::sort比std::qsort内联的事实要快670%.我测试了自己,我看到qsort更快:(!有谁可以帮我解释这个奇怪的行为?
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
const size_t LARGE_SIZE = 100000;
struct rnd {
int operator()() {
return rand() % LARGE_SIZE;
}
};
int comp( const void* a, const void* b ) {
return ( *( int* )a - *( int* )b );
}
int main() {
int ary[LARGE_SIZE];
int ary_copy[LARGE_SIZE];
// generate random data
std::generate( ary, ary + LARGE_SIZE, rnd() );
std::copy( ary, ary …Run Code Online (Sandbox Code Playgroud) 是否有任何简单的方法可以通过RCpp中的两个(或多个或一个)列来订购DataFrame?
网上有很多排序算法,或者我可以使用std::sortDataFrame的包装器,但我想知道RCpp或RCppArmadillo中是否有可用的东西?
我需要将此排序/排序作为另一个函数的一部分
DataFrame myFunc(DataFrame myDF, NumericVector x) {
//// some code here
DataFrame myDFsorted = sort (myDF, someColName1, someColName2) // how to sort??
//// some code here
}
Run Code Online (Sandbox Code Playgroud)
我想避免order在RCpp中访问R的功能(为了保持RCpp代码的速度).
非常感谢