Re: [R] matrix operation

From: Tuszynski, Jaroslaw W. <JAROSLAW.W.TUSZYNSKI_at_saic.com>
Date: Mon 10 Oct 2005 - 22:22:11 EST


 There a re a few ways to do it without loop. Here is one:  

 dat = matrix(runif(100), 50,2)
 dat[,1] = dat[,1] >= dat[,2]

 Jarek

====================================================\==== 
 Jarek Tuszynski, PhD.                           o / \ 
 Science Applications International Corporation  <\__,|  
 (703) 676-4192                                   ">  \ 
 Jaroslaw.W.Tuszynski@saic.com                     `   \ 



-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch
[mailto:r-help-bounces@stat.math.ethz.ch] Sent: Friday, October 07, 2005 6:02 PM
To: r-help@stat.math.ethz.ch
Subject: [R] matrix operation

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

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 Mon Oct 10 22:31:02 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:36:59 EST