s-news
[Top] [All Lists]

[S] Element processing in a table/matrix

To: s-news@wubios.wustl.edu
Subject: [S] Element processing in a table/matrix
From: Steve Friedman <friedman@gis.umn.edu>
Date: Thu, 29 Apr 1999 17:56:56 -0500
Organization: Dept. of Forest Resources, University of Minnesota
Sender: owner-s-news@wubios.wustl.edu
Greetings,

I've been working at this for too long and making no headway. Perhaps
fresher
more experienced minds can help.

I have a matrix and I need to multiply every element in the matrix the
column number of the
matrix.  Solutions seem to be avoiding me, help is greatly appreciated.
Is there an approach
that does not require the for loops?

Part of the function I've written to do this:

function(x)   {
 y <- table(x$imagery, x$histogram)
     new <- matrix(1:nrow(y) * ncol(y), ncol = ncol(y))
       for(j in 1:nrow(y))
             for(i in 1:ncol(y))
      new[i, j] <- y[i, j] * i
 return(new)
#   actually goes on to do some addtional computations here, rather than
just returning (new).
}

Assistance is greatly appreciated.

Thanks
Steve


-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>