Created
April 14, 2018 09:07
-
-
Save artemklevtsov/3d27e90e9285364f08e0b1b45b087aea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [[Rcpp::plugins(cpp11)]] | |
#include <Rcpp.h> | |
using namespace Rcpp; | |
template <int RTYPE> | |
Vector<RTYPE> na_locf_impl(Vector<RTYPE> x) { | |
std::size_t n = x.size(); | |
auto v = x[0]; | |
for (std::size_t i = 0; i < n; ++i) { | |
if (Vector<RTYPE>::is_na(x[i])) | |
x[i] = v; | |
else | |
v = x[i]; | |
} | |
return x; | |
} | |
// [[Rcpp::export]] | |
SEXP na_locf(SEXP x) { | |
RCPP_RETURN_VECTOR(na_locf_impl, x); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment