Compare values of two vectors

589 views Asked by At

I have two vectors:

 a <- c(23,43,54)
 x <- c(1,543,65,89)

I would like to have a vector y of dimension 4 - (dim(x)) which indicates how many values of the vector a are upper than each coefficient of the vector x.

Is there a function that does this task?

1

There are 1 answers

0
akrun On BEST ANSWER

Try

 colSums(outer(a, x, FUN='>'))

Or

 library(data.table)
 CJ(a,x)[,sum(V1>V2) ,V2]$V1