Moreno Mancosu
2009-Sep-21 14:19 UTC
[R] Combine vectors in order to form matrixes with combn
Hello! I've a problem with the combn function and a set of vector. I would like to make a simple combination where, instead of scalars, i would like to combine vector, in order to form matrixes. In other words, i have nineteen 6-items vectors (for example coef1-coef19), that i would like to combine in n!/k!(n-k)! 6x6 matrixes. I tried with a code like this mma <- combn(c(coeff1,coeff2,...,coeff19),function(x) matrix(x,6,6)) but i think that R doesn't recognize that these are not scalars. In fact the error is: Errore in matrix(r, nrow = len.r, ncol = count) : invalid 'ncol' value (too large or NA) Inoltre: Warning message: In combn(c(coeff1, coeff2, coeff3, coeff4, coeff5, coeff6, coeff7, : si ? prodotto un NA per coercizione Some ideas? Thanks in advance, Moreno Tutto Incluso Light: chiami e navighi senza limiti a soli 9,95 euro al mese. Gratis la Sim Tiscali Mobile con 25 euro di traffico! ATTIVA ORA http://abbonati.tiscali.it/telefono-adsl/prodotti/tc/tuttoincluso_light/
Bryan Keller
2009-Sep-21 14:46 UTC
[R] Combine vectors in order to form matrixes with combn
Moreno, I don't understand exactly what it is you are trying to do. Can you explain what you want your matrices to look like? Perhaps give an example. Bryan ------------- Bryan Keller, Doctoral Student/Project Assistant Educational Psychology - Quantitative Methods The University of Wisconsin - Madison ----- Original Message ----- From: Moreno Mancosu <nomero at tiscali.it> Date: Monday, September 21, 2009 9:21 am Subject: [R] Combine vectors in order to form matrixes with combn To: r-help at r-project.org> Hello! > > I've a problem with the combn function and a set of vector. I > would like to make a simple combination where, instead of scalars, i > would like to combine vector, in order to form matrixes. > In other > words, i have nineteen 6-items vectors (for example coef1-coef19), > that > i would like to combine in n!/k!(n-k)! 6x6 matrixes. > > I tried with a > code like this > > mma <- combn(c(coeff1,coeff2,...,coeff19),function(x) > matrix(x,6,6)) > > but i think that R doesn't recognize that these are not > scalars. In fact the error is: > > Errore in matrix(r, nrow = len.r, ncol > = count) : > invalid 'ncol' value (too large or NA) > Inoltre: Warning > message: > In combn(c(coeff1, coeff2, coeff3, coeff4, coeff5, coeff6, > coeff7, : > si ? prodotto un NA per coercizione > > > Some ideas? > > Thanks > in advance, > > Moreno > > > Tutto Incluso Light: chiami e navighi senza limiti a soli 9,95 euro al > mese. Gratis la Sim Tiscali Mobile con 25 euro di traffico! ATTIVA ORA > > http://abbonati.tiscali.it/telefono-adsl/prodotti/tc/tuttoincluso_light/ > > ______________________________________________ > 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.
Moreno Mancosu
2009-Sep-21 15:12 UTC
[R] Combine vectors in order to form matrixes with combn
> Moreno, > > I don't understand exactly what it is you are trying todo. Can you explain what you want your matrices to look like? Perhaps give an example.> > BryanDear Bryan, let's try with an example: i have 8 column vectors v1<-matrix(c(2,5,6,8)) v2<-matrix(c(3,7,9,11)) v3<-matrix(c(13,4,2,7)) v4<-matrix(c(3.4,6,11,21)) v5<-matrix(c (1,9,45,3)) v6<-matrix(c(2,76,4,2)) v7<-matrix(c(34,7,8,1)) v8<-matrix(c (2,6,1,9)) I would like to form a combination of theese vectors in order to obtain a set of matrixes in the form "k-combinations from a set" of n elements, when the set is the number of vectors (in this case 8) and k is the number of columns (in this case 4): in this example, i would like to obtain matrix_1 [,1] [,2] [,3] [,4] [1,] 2 3 13 3.4 [2,] 5 7 4 6.0 [3,] 6 9 2 11.0 [4,] 8 11 7 21.0 matrix_2 [,1] [,2] [,3] [,4] [1,] 2 3 13 1 [2,] 5 7 4 9 [3,] 6 9 2 45 [4,] 8 11 7 3 matrix_3 [,1] [,2] [,3] [,4] [1,] 2 3 13 2 [2,] 5 7 4 76 [3,] 6 9 2 4 [4,] 8 11 7 2 [...] matrix_n!/k!(n-k!) [,1] [,2] [, 3] [,4] [1,] 1 2 34 2 [2,] 9 76 7 6 [3,] 45 4 8 1 [4,] 3 2 1 9 I hope I was more clear! However, thanks in advance, Moreno Tutto Incluso Light: chiami e navighi senza limiti a soli 9,95 euro al mese. Gratis la Sim Tiscali Mobile con 25 euro di traffico! ATTIVA ORA http://abbonati.tiscali.it/telefono-adsl/prodotti/tc/tuttoincluso_light/