[R] ignoring objects containing NaN's in a recursive function

Mills, Jason Jason.Mills at afhe.ualberta.ca
Tue Mar 14 19:59:55 CET 2006


General question:
I have written a function that performs a permutation test.  I use the
function "sample" to randomize my data, then I call on another function
I wrote to analyze the randomized data.  This process repeats "n"
times-- 10, 100 or whatever.

The function applied to the randomized data creates a matrix and
sometimes the matrix contains NaN's.  I would like my function to simply
ignore any matrices that contain NaN's and continue to cycle until it
has generated "n" matrices without any NaN's.  I am aware of the
function "is.nan", but I'm not sure how to fit it in.

Here's the section of code that needs improvement:

for (i in 1:n){
	S[,,]= sample (Y[,,])

n= number of randomizations
S= array to store randomized data
Y= original data array
dig= the matrix returned by the function "auto"
out= matrix that collects the first row of each "dig" matrix up to "n"

Sometimes "dig" includes NaN's.  I want the function to ignore those
"dig"s but keep working until it has generated "n" matrices that contain
no NaN's.  

How could I do this?


Jason Mills

More information about the R-help mailing list