r - How to use the outer() to calculate the median between each vector? -


i hope title isn't confusing...

basically, have 2 vectors each of n length. want transmute these 2 vectors n*n matrix (i.e. 2 vectors contains 2 numbers each becomes 2*2 matrix), each position in matrix median of each position of 2 vectors.

for example:

a<-as.vector(1,5) b<-as.vector(1,5) 

using outer() gives me 2*2 matrix

  1 5 1 5 

but, how fill empty matrix median values between each unique combination? answer should this:

1 3 3 5 

try

 outer(a, b, fun= vectorize(function(x,y) median(c(x,y))))  #     [,1] [,2]  #[1,]    1    3  #[2,]    3    5 

data

a <- c(1,5) b <- 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -