[R] matrix operation

From: Dhiren DSouza <dhiren22_at_hotmail.com>
Date: Sat 08 Oct 2005 - 08:01:41 EST


Hello:

I have a matrix 'dat' with 2 columns.

I have the following code:

for (i in 1:nrows(dat))
{
  if (dat[i,1] < dat[i,2])
    {
      dat[i,2]<-0
    }

   else
   {

     dat[i,2]<-1
   }

Is there a way to accomplish this without the for loop?

Thank you.

-Dhiren



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Oct 08 08:09:07 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:39 EST