[R] matrix to a C function
Christophe Genolini
cgenolin at u-paris10.fr
Sat Jan 23 17:04:56 CET 2010
Hi the list,
Is there a way to give a matrix to a C function, and then to use it as a
matrix ?
I write a function to print a matrix, but I use it as a vector :
1. void printMatrix(double *mTraj,int *nbCol, int *nbLigne){
2. int i=0,j=0;
3. for(i=0 ; i < *nbLigne ; i++){
4. for(j=0 ; j < *nbCol ; j++){
5. Rprintf(" %f",mTraj[i * *nbCol + j]);
6. }
7. Rprintf("\n");
8. }
9. }
I would like to use it as a matrix (line 5 changes) :
1. void printMatrix(double *mTraj,int *nbCol, int *nbLigne){
2. int i=0,j=0;
3. for(i=0 ; i < *nbLigne ; i++){
4. for(j=0 ; j < *nbCol ; j++){
5. Rprintf(" %f",mTraj[i,j]);
6. }
7. Rprintf("\n");
8. }
9. }
It does not work, but is there an solution close to this ?
Thanks.
Christophe
More information about the R-help
mailing list