VectortoOrderedMap_SNP_counts
C++ Function Reference
1 Signature
std::map< double, double > BigDataStatMeth::VectortoOrderedMap_SNP_counts(Eigen::VectorXd vdata)2 Description
Converts a vector to an ordered map of value frequencies.
3 Parameters
vdata(Eigen::VectorXd): Input vector of values
4 Returns
std::map<double, double> Map of value-frequency pairs
5 Details
Creates a map where keys are unique values from the input vector and values are their frequencies of occurrence.
6 Caller Graph
7 Source Code
NoteImplementation
File: inst/include/hdf5Utilities/hdf5ImputeData.hpp • Lines 101-128
inline std::map<double, double> VectortoOrderedMap_SNP_counts( Eigen::VectorXd vdata)
{
std::map<double, double> mapv;
try
{
int position = 0;
std::vector<double> v(vdata.data(), vdata.data()+vdata.size());
std::sort(v.begin(), v.end() ); // Sort vector to optimize search and count
for (size_t i = 0; i <= *std::max_element(v.begin(), v.end()) ; ++i)
{
double mycount = std::count(v.begin() + position, v.end(), i);
mapv[i] = mycount;
position = position + mycount;
}
} catch(std::exception &ex) {
Rf_error( "c++ exception VectortoOrderedMap_SNP_counts : %s", ex.what());
return std::map<double, double>();
} catch(...) {
Rf_error("c++ exception VectortoOrderedMap_SNP_counts (unknown reason)");
return std::map<double, double>();
}
return mapv;
}8 Usage Example
#include "BigDataStatMeth.hpp"
// Example usage
auto result = VectortoOrderedMap_SNP_counts(...);