thanks, Berend.  Both of your code works great.  Is there a function that
can do it?

Something like this:
x <- matrix(NA, nrow=15, ncol=2)
for(i in 1:15){
   x[i,] <- sample(c(NA, 20, 77), 2, prob=c(0.2, 0.3, 0.4))
}

> x

      [,1] [,2]

 [1,]   NA   77

 [2,]   77   NA

 [3,]   NA   77

 [4,]   77   20

 [5,]   77   20

 [6,]   77   20

 [7,]   20   NA

 [8,]   77   20

 [9,]   77   NA

[10,]   77   NA

[11,]   77   20

[12,]   20   77

[13,]   NA   77

[14,]   77   20

[15,]   77   20

I want to have a column of 15 samples without NA's.  Is there an R function
like ifelse()?

Mike

On Fri, Nov 30, 2012 at 12:24 AM, Berend Hasselman <bhh@xs4all.nl> wrote:

>
> On 30-11-2012, at 05:47, C W wrote:
>
> > David,
> > Your results is,
> >
> >> samples
> >
> > [1] 111  NA 111  NA 111  NA 111  NA 111  NA
> > It still has NA's in it. I want it look like this,
> >
> >> samples
> >
> > [1] 111  111  111  111 111
>
> You don't need the for loop at all.
>
> samples <-  x[x<200]
>
> or
>
> samples <-  x[which(x<200)]
>
> Your for loop should look something like this
>
> k <- 1
> for(i in 1:10){
>   if(x[i]<200){
>        samples[k] <- x[i]
>        k <- k+1
>    }
> }
> na.omit(samples)
>
> Berend
>
>
>

	[[alternative HTML version deleted]]


