I've got two files: main.R and mv.cpp.
main.R:
main.R
library(Rcpp)
r <- data.frame(replicate(10, sample(0:10, 10000, replace = TRUE)))
mv(r)
and mv.cpp
#include <Rcpp.h>
using namespace Rcpp;// [[Rcpp::export]]
void mv(Rcpp::DataFrame x){
int n = 0;
int nrow = x.nrow();
int ncol = x.ncol();
int mv = 0;for (int t =0; t < 10 + 0*nrow; t++){ mv = x[0, t]; for (int d = 0; d < ncol; d++){ if (NumericVector::is_na(x[d,t])){ x[d,t ] = mv; n++; } else { mv = x[d, t]; } } } return;
}
I compile mv.cpp and then run main.R and get the error message:
Error in mv(r) : Expecting a single value: [extent=10000].
I've tried changing mv.cpp from void to int and still get the same error.