From kriegstn at yahoo.de  Tue Mar  7 13:05:14 2006
From: kriegstn at yahoo.de (Bernd Kriegstein)
Date: Tue, 7 Mar 2006 13:05:14 +0100 (CET)
Subject: [Rd] double pointer matrix
Message-ID: <20060307120514.75381.qmail@web27413.mail.ukl.yahoo.com>

Hello,

I'm having some difficulty to understand how I could
take the proper result from the following listing:

-- cut ---
#include <stdlib.h>
#include <R.h>
#include <Rmath.h>

void retMat ( double **y, int *n, int *m, double *a,
double *b) {
        int i, j;
        y = malloc( (*n) * sizeof( double ) );
        for (i=0; i<*n; i++) {
                y[i] = malloc ( (*m) * sizeof( double
) );
        }
        
        GetRNGstate();

        for (i=0; i<*n; i++) {
                for (j=0; j<*m; j++) {
                        y[i][j] = (i+1)*(j+1)*rbeta(
*a, *b );
                }
        }
        
        PutRNGstate();
}
---
I understand that I will have to make the matrix
initialized in the double for loop above to be somehow
visible as a vector, because of the way that the
matrix elements are passed in the argument when used
in the R space. Is there a way to accomplish this?

Thanks for any answers,

- b.



[Rd] double pointer matrix
Bernd Kriegstein