Closed RobinHankin closed 1 year ago
It is possible to replace the binary operator *
with +
if you are sure that the cycles of x
and y
are distinct:
set.seed(0)
x <- rperm(5,r=4)
y <- capply(rperm(3,r=4),function(x){x+100})
do.call("c",apply(expand.grid(seq_along(x),seq_along(y)),1,function(v){x[v[1]] + y[v[2]]},simplify=FALSE))
[1] (1,2)(3,4)(101,103,104,102) (3,4)(101,103,104,102) (1,3,4)(101,103,104,102) (1,3,4,2)(101,103,104,102) (1,2,4)(101,103,104,102)
[6] (1,2)(3,4)(102,104) (3,4)(102,104) (1,3,4)(102,104) (1,3,4,2)(102,104) (1,2,4)(102,104)
[11] (1,2)(3,4)(102,104,103) (3,4)(102,104,103) (1,3,4)(102,104,103) (1,3,4,2)(102,104,103) (1,2,4)(102,104,103)
Or even
do.call("c",apply(expand.grid(seq_along(x),seq_along(y)),1,function(v){x[v[1]] %~% y[v[2]]},simplify=FALSE))
[1] FALSE FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE TRUE FALSE TRUE
(although in that case it might be better to return a matrix).
fixed in df16a5b
Given two vectors
x
andy
of permutations, it would be nice to useouter()
to multiply each element ofx
with each element ofy
. Functioncayley()
has some of this functionality but is rather obscurely written: the intent is to produce nice tables of (closed) subgroups of the symmetric group $S_n$, rather than a general outer product calculation.