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
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
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.
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
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 ) ;