[R] Help on apply() function

Paul Smith phhs80 at gmail.com
Wed Aug 30 12:14:52 CEST 2006


On 8/30/06, Mark Lyman <mark.lyman at gmail.com> wrote:
> > I have a problem with apply function. I have to two matrices of dimension of
> > one column but n rows. I have to check whether one matrix is greater than
> > other by going thru each row (ie) using if condition to check one matrix
> > with another matrix.
> >
> > I like to use apply() function to this approach. That is apply function
> > between two matrices. I searched for examples online but I couldn't find
> > any.
> >
> > I don't know how to loop thru the matrices.
>
> You can use the functions all.equal with the function isTRUE (see ?all.equal) to
> check if two objects are nearly equal (within a certain tolerance). Or you can
> use identical (see ?identical) to check if they are exactly the same. See the
> examples in the help for identical.

A possible solution could be:

> x <- 1:5
> x
[1] 1 2 3 4 5
> y <- 2:6
> y
[1] 2 3 4 5 6
> all((y-x)>0)
[1] TRUE

The result TRUE means that each element of y is greater than the
homologous element in x.

Paul



More information about the R-help mailing list