[R] comparing two vectors

hadley wickham h.wickham at gmail.com
Sun Jun 10 09:27:52 CEST 2007


On 6/10/07, gallon li <gallon.li at gmail.com> wrote:
> Suppose I have a vector A=c(1,2,3)
>
> now I want to compare each element of A to another vector L=c(0.5, 1.2)
>
> and then recode values for sum(A>0.5) and sum(A>1.2)
>
> to get a result of (3,2)
>
> how can I get this without writing a loop of sums?

How about colSums(outer(A, L, ">"))

Hadley



More information about the R-help mailing list