Displaying 3 results from an estimated 3 matches for "get_dimnames".
2003 May 21
2
moving onto returning a data.frame?
...SEXP m_out;
SEXP nms;
if( !isMatrix( m_in ) )
{
error("m_in must be a matrix");
}
mdims = INTEGER( GET_DIM( m_in ) );
n = mdims[0];
p = mdims[1];
PROTECT( m_out = NEW_NUMERIC( p ) );
PROTECT( m_in = AS_NUMERIC( m_in ) );
PROTECT( nms = GET_COLNAMES( GET_DIMNAMES( m_in ) ) );
/* here you'll disect the incoming data.frame into the vectors you'll
pass into your simulation code */
/* get the vectors based on the column names to make sure the sequence
isn't important */
/* crunch, crunch, crunch */
/* assign the results into the o...
2009 Mar 27
0
imporving performance of slicing on matrices and S4 their derivatives
...ting A COPY of @.Data, keeping
dimnames */
int nrow = Rf_nrows(m);
int ncol = Rf_ncols(m);
SEXP res, dim;
PROTECT(res = allocVector(REALSXP, nrow*ncol));
PROTECT(dim = allocVector(INTSXP, 2));
INTEGER(dim)[0] = nrow;
INTEGER(dim)[1] = ncol;
SET_DIM(res, dim);
if (GET_DIMNAMES(m)!= R_NilValue)
SET_DIMNAMES(res, Rf_duplicate(GET_DIMNAMES(m)));
if (ncol>0 && nrow>0)
memcpy(REAL(res), REAL(m), nrow*ncol*sizeof(double));
UNPROTECT(2);
return res;"
mcols = cfunction(signature(m="matrix"), body=body,
includes="...
2001 Dec 14
2
colSums in C
Hi, all!
My project today is to write a speedy colSums(), which is a function
available in S-Plus to add the columns of a matrix. Here are 4 ways to do it,
with the time it took (elapsed, best of 3 trials) in both R and S-Plus:
m <- matrix(1, 400, 40000)
x1 <- apply(m, 2, sum) ## R=16.55 S=52.39
x2 <- as.vector(rep(1,nrow(m)) %*% m) ## R= 2.39 S= 8.52
x3 <-