[R] Comparing each component of vector to each component of a Matrix.

Rolf Turner r.turner at auckland.ac.nz
Wed Mar 11 10:46:42 CET 2015


On 11/03/15 20:01, Frederic Ntirenganya wrote:
> Hi All,
>
> I need a help on a loop which can compare the each component of vector to
> each component of a Matrix.
>
> Let a vector b = {b1, b2, ...,bn} and 2x2  matrix A = Aij.
>
> I need to compare each component of the vector with each component of a
> matrix and print 1 if the component is less or equal to one and print 0
> otherwise.
>
> bi <= Aij, print 1 and 0 otherwise.
>
> Any help is appreciated.

outer(b,A,"<=")+0

cheers,

Rolf Turner

-- 
Rolf Turner
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
Home phone: +64-9-480-4619



More information about the R-help mailing list