Re: [Rcpp-devel] Easy way to subset a matrix

2011-09-20 Thread c s
On Wed, Sep 21, 2011 at 4:00 PM, Noah Silverman wrote: > Nice suggestion, but it may not work for what I'm trying to do. > I'm building up a matrix of values over a time series as part of a big loop. >  At certain iterations, I need to calculate some summary statistics on a few > things.  In R, it

Re: [Rcpp-devel] Easy way to subset a matrix

2011-09-20 Thread Noah Silverman
Nice suggestion, but it may not work for what I'm trying to do. I'm building up a matrix of values over a time series as part of a big loop. At certain iterations, I need to calculate some summary statistics on a few things. In R, it is trivial to subset any part of a matrix. Not sure to do

Re: [Rcpp-devel] Easy way to subset a matrix

2011-09-20 Thread Zarrar Shehzad
I am not sure if there are native functions in Rcpp but you could use RcppArmadillo to solve your problem. So say Xs = x: // Convert from SEXP => Rcpp => Arma Rcpp::NumericMatrix Xr(Xs); arma::mat X(Xr.begin(), Xr.nrow(), Xr.ncol(), false); // Get subset of matrix and calculate variance // (i.e.

[Rcpp-devel] Easy way to subset a matrix

2011-09-20 Thread Noah Silverman
Hello, I want to calculate the variance of a subset of a matrix column. For example, if I wanted the variance of items 3-10 in column 5. In R, this would be: x <- matrix(rnorm(100), nrow=10, ncol=10) varx <- var(x[3:10,5]) In Rcpp, I can construct a matrix object Rcpp::NumericMatrix x The var

Re: [Rcpp-devel] Strange behavior of NumericMatrix

2011-09-20 Thread Romain François
Hello, On a more cosmetic level, you could use the pow function from sugar: require( Rcpp ) require( inline ) fx<- cxxfunction( signature(), plugin="Rcpp", body=" Rcpp::NumericMatrix out_xx(10, 4); for(int i=0; i<4; i++) out_xx(_,i) = pow( seq(0, 9), i ) ;