You may find it easier to use the Rcpp class NumericMatrix than to use RcppArmadillo. Detection of NA's is built in to R and Rcpp classes but not RcppArmadillo. For each pair of columns, run a loop that checks for NA's at each position in each column, skips the position if NA's are detected and otherwise increments the squared sums, cross-product and number of elements. On Oct 9, 2012 9:53 AM, "[email protected]" <[email protected]> wrote:
> Hi, > > I have written small code in C++ using Armadillo and inline with > RcppArmadillo package. > The input is data.marix(X). Some cells might be NAs. Example in R: X = > matrix(sample(c(rnorm(10*9.9),NA)),ncol=10) > > I am calculating conditional correlation on columns of that matrix, just > picking vectors, so cor(X,Y). > The problem is that sometimes I might have empty cell in one or both > vectors, in that case I would like to skip that row, and procede with > calculating Pearson's correlation on remaining data. I know that there will > be difference in degrees of freedom, but I have over 100 rows, so skiping > few shouldnt matter that much. > > Basically my question boils down to solving the problem: > How to find which colvec cells are nan, and remove this index from both X > and Y colvec, before calculating correlation. > > I would be very grateful for help, > > Kind regards, > Mateusz Kaduk > > _______________________________________________ > Rcpp-devel mailing list > [email protected] > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel >
_______________________________________________ Rcpp-devel mailing list [email protected] https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
