41 return std::count_if(row.cbegin(),row.cend(),[](
auto el){return std::isnan(el);}) == tot_cols ? true :
false;
56 if (x.nrow() == 0 || x.ncol() == 0)
58 std::string error_message1 =
"Empty data matrix";
59 throw std::invalid_argument(error_message1);
62 int tot_cols = x.ncol();
63 std::set<int> rows_to_be_kept;
64 for (
int i = 0; i < x.nrow(); ++i) {
if (!
is_row_all_nan(x.row(i),tot_cols)) { rows_to_be_kept.insert(i);}}
66 if (rows_to_be_kept.empty())
68 std::string error_message2 =
"Only-NaNs data matrix";
69 throw std::invalid_argument(error_message2);
72 return rows_to_be_kept;
89 Rcpp::NumericMatrix x_clean(rows_to_be_kept.size(),x.ncol());
90 int counter_row_clean = 0;
91 std::for_each(rows_to_be_kept.cbegin(),rows_to_be_kept.cend(),[&x,&x_clean,&counter_row_clean](
auto el){x_clean.row(counter_row_clean)=x.row(el); counter_row_clean++;});
Contains the class to remove (dummy and not dummy) NaNs.
std::set< int > rows_entire_NaNs(const Rcpp::NumericMatrix &x)
Identifying rows of only NaNs.
Definition removing_nan_cleaner_imp.hpp:54
bool is_row_all_nan(const Rcpp::NumericMatrix::ConstRow &row, int tot_cols)
Function checking if a row is entirely made by NaNs.
Definition removing_nan_cleaner_imp.hpp:39
Rcpp::NumericMatrix removing_NaNS_entire_rows(const Rcpp::NumericMatrix &x, const std::set< int > &rows_to_be_kept)
Removing rows of only NaNs.
Definition removing_nan_cleaner_imp.hpp:87