[R] Matrix manipulation

2011-04-01 Thread Joseph N. Paulson
Hi all!

I have a vector, let's say for example int - sample(1:20,10);
for now:

now I have a matrix...
M = m x n
where the first column is a feature column and most likely shares at least
one of the int (interesting) numbers.

I want to extract the rows where int[] = M[,1]

I thought:
rownames(int)-int;
rownames(M)-M[,1];

M[rownames(int),] would work, but it doesn't... (I assume because I have
rownames(int) that are not found in M[,1]. Neither does,
rownames(M)==rownames(int)...

Any help would be greatly appreciated!

Thank you!

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] C module causing rounding errors?

2010-07-09 Thread Joseph N. Paulson
Sorry for not including enough information everyone.

I have quite a bit of code, so I will just enter relevant pieces...

This is how I call C from R:

The tstats are tstatistics (difference of mean, divided by sqrt of S1+S2)
from an unpermuted matrix. The c code is below...

dyn.load(testp.so)
obj-.C(testp,ptests=as.array(permuted_ttests),as.integer(B),permuted1=as.array(permuted),matrix=as.array(Imatrix),
as.integer(ncols), as.integer(nrows),as.integer(g)*,as.array(abs(tstats)*
),pvalues=as.array(ps))

to test, I decided not to permute my matrix and just send it the original
matrix, Imatrix. Everything in C is a double, or if I use an integer, I cast
it to a double (to divide and get mean, etc). I then compare the values of
the tstats that I sent into C and the tsats I calculate within C...

The following is my C code:

void testp(double *permuted_ttests,int *B,double *permuted,double
*Imatrix,int *nc,int *nr,int *g,*double *Tinitial*,double *ps) {

after which, using the variable above I take the mean of certain elements
(currently the unpermuted matrix to test) via other functions using the same
double and pointers and I store them in C1 and C2 and solve for an absolute
T statistic - and print it (I erased the Ts earlier).


for (i=0; i*nr; i++){
  xbardiff = C1[i][0]-C2[i][0];
  denom = sqrt(C1[i][2]+C2[i][2]);
*  Ts[i]=fabs(xbardiff/denom);*
*  Rprintf(%f Ts\n,Ts[i]);*
*
  if (fabs(Ts[i])fabs(Tinitial[i])){ //summing of permueted_ttests
counter[i]++;
 Rprintf(ts %f and tinitial %f \n, Ts[i],Tinitial[i]);
  }
*
etc...
The issue here - is that I get a few that when printed it appears that they
were rounded up - causing my counter[i] to ++ in some cases.

Should I send more code?

Sorry and thank you very much,




On Fri, Jul 9, 2010 at 6:18 AM, Duncan Murdoch murdoch.dun...@gmail.comwrote:

 Joseph N. Paulson wrote:

 Hi all!

 I am currently writing a C-module for a for loop in which I permute
 columns
 in a matrix (bootstrapping) and I send a couple of variables into C
 initially. All of it is working, except the initial values I send to R are
 rounded/truncated (I believe rounded).

 I am using a 32 bit machine to compile, I am using (I believe) 32 bit
 R

 While debugging I print the values I am sending to C, and then I print the
 same values using Rprintf and the number gets rounded to 10^-6, which is
 actually causing some errors for me. Is there any way to correct/prevent
 the
 error?


 sample output from R

  [1,]  1.000
  [2,]  1.0256242
  [3,]  1.1826277
  [4,] -0.6937246
  [5,]  1.3633604

 sample output from C
 1.00
 1.025624
 1.182628
 0.693725
 1.363360



 It looks as though you are confusing the display of numbers with their
 internal values.  R is printing 7 decimal places, C is printing 6.  As far
 as we can tell, that's the only difference.

 Duncan Murdoch

 [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
 -  Joseph N. Paulson

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] C module causing rounding errors?

2010-07-08 Thread Joseph N. Paulson
Hi all!

I am currently writing a C-module for a for loop in which I permute columns
in a matrix (bootstrapping) and I send a couple of variables into C
initially. All of it is working, except the initial values I send to R are
rounded/truncated (I believe rounded).

I am using a 32 bit machine to compile, I am using (I believe) 32 bit R

While debugging I print the values I am sending to C, and then I print the
same values using Rprintf and the number gets rounded to 10^-6, which is
actually causing some errors for me. Is there any way to correct/prevent the
error?


sample output from R

 [1,]  1.000
 [2,]  1.0256242
 [3,]  1.1826277
 [4,] -0.6937246
 [5,]  1.3633604

sample output from C
1.00
1.025624
1.182628
0.693725
1.363360

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.