[R] matrix operation

Dhiren DSouza dhiren22 at hotmail.com
Sat Oct 8 00:01:41 CEST 2005


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




More information about the R-help mailing list