R, looking for a faster and more efficient way (package, code, parallel processor) than basic R
I am using basic R for combinations.
For example, let's say I have a matrix with 2 rows and 5 columns:
z<-matrix(c(1, 2, 1, 3, 2, 2, 1, 3, 2, 1),nrow=2,ncol=5,byrow = TRUE)
[,1] [,2] [,3] [,4] [,5]
[1,] 1 2 1 3 2
[2,] 2 1 3 2 1
I am using the following code for combinations of 3 column sets:
l<- apply(X = combn(seq_len(ncol(z)), 3),MAR = 2,FUN = function(jj) {apply(z[, jj], 1, paste, collapse="") })
This will export what I need:
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] "121" "123" "122" "113" "112" "132" "213" "212" "232" "132"
[2,] "213" "212" "211" "232" "231" "221" "132" "131" "121" "321"
The problem starts when I use big data in a matrix, for example when I have a matrix with 15000 rows and 17 columns and I need combinations of 10 column sets.
In this example, this export takes a very long time.
Is there a faster and more efficient way than basic R (maybe some packages or code or using parallel processors) for this example combinations?
I am using Windows 7 64bit, FX 8320, 16GB RAM.
+3
source to share
No one has answered this question yet
Check out similar questions: