Cartesian product table for an algebraic relation in R -


i have 1 or 2 numerical vectors, e.g. x <- c(1, 2, 3). want create graphical representation of relation arb, r algebraic formula such a + b (used in example below) or a / (a + b) (with a,b element of x, including a = b, i.e. reflexive relation).

the structure should be:

r     b   c  a+a a+b a+c b  b+a b+b b+c c  c+a c+b c+c 

so output (for sample vector x above):

r   1   2   3 1   2   3   4 2   3   4   5 3   4   5   6 

r can comparison such a = b or a > b^2 / a, result in table not number true or false.

is there function create such table in r?

x <- 1:3 outer(x,x,"+")       [,1] [,2] [,3] [1,]    2    3    4 [2,]    3    4    5 [3,]    4    5    6 

you can pass other functions outer, e.g.

outer(x,x,"==")  outer(x,x,fun=function(a,b){a > (b^2 / a)}) 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -