[Rcpp-devel] Templated function that removes all the NA values

leo leodidonato at gmail.com
Thu Apr 11 18:29:26 CEST 2013

Hi to all,

I was investigating a way to write with Rcpp a function that removes all
the NA values in the input vector.

And before doing so, I was playing with Rcpp, writing this function:


  Vector<INTSXP> na_test(const Vector<INTSXP>& x) {
    return setdiff(x, Vector<INTSXP>::create(::traits::get_na<INTSXP>()));

That works in this way:

na_test(c(1, NA, NA, 1, 2, NA))# [1] 1 2

How can I write a generalized version of this function, for example?

I've made an attempt (see stackoverflow related
It compiles but it doesn't work as expected.

Any suggest or example?

Thanks in advance,

Leonardo Di Donato
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130411/9b6795eb/attachment.html>

More information about the Rcpp-devel mailing list