RobinHankin / permutations

https://robinhankin.github.io/permutations/
5 stars 3 forks source link

permutation matrix #13

Closed RobinHankin closed 5 years ago

RobinHankin commented 5 years ago

The package does not have functionality to calculate a permutation matrix. The underlying R idiom is easy. Given a permutation p in word form, then

M <- matrix(0,size(p),size(p))
M[cbind(seq_len(size(p)),unclass(p)[1,])] <- 1
M

and this should work, although only for single permutations. Note that as.matrix.word() does something different, and this fact should be documented in permutation.Rd.