[R] maxtrix to permutation vector

Gabor Grothendieck ggrothendieck at gmail.com
Fri May 29 21:04:42 CEST 2009


Try this:

> m <- matrix(1:9, 3, dimnames = list(R = letters[1:3], C = LETTERS[1:3]))
> as.data.frame.table(m, responseName = "Value")
  R C Value
1 a A     1
2 b A     2
3 c A     3
4 a B     4
5 b B     5
6 c B     6
7 a C     7
8 b C     8
9 c C     9



On Fri, May 29, 2009 at 2:08 PM, Ian Coe <ICoe at connectcap.com> wrote:
> Hi,
>
>   Is there a way to  convert a matrix into a vector representing all
> permutations of values and column/row headings with native R functions?
> I did this with 2 nested for loops and it took about 25 minutes to run
> on a  ~700x700 matrix.  I'm assuming there must be a smarter way to do
> this with R's vector commands, but being new to R, I'm having trouble
> making it work.
>
>
>
> Thanks,
>
> Ian
>
>
>
>     [a] [b] [c]
>
> [d]    1    4    7
>
> [e]    2    5    8
>
> [f]    3    6    9
>
>
>
> a d 1
>
> a e 2
>
> a f 3
>
> b d 4
>
> b e 5
>
> b f 6
>
> c d 7
>
> c e 8
>
> c f 9
>
>
>
>
>
>
>
>
>
> Ian Coe
>
>
>
> Connective Capital Management, LLC
>
> 385 Homer Ave.
>
> Palo Alto, CA 94301
>
> (650) 321-4826 ext. 03
>
>
>
> CONFIDENTIALITY NOTICE: This e-mail communication (inclu...{{dropped:23}}
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list