I have a vector x of 1,344 unique strings. I want to create a matrix that gives me all possible groups of three values, regardless of order, and exports them to csv.
I am running R on EC2 on an instance of m1.large with 64 bit Ubuntu. When using combn (x, 3), I get an error from memory:
Error: cannot allocate vector of size 9.0 Gb
The size of the resulting matrix is ββC1344.3 = 403,716,544 rows and three columns, which is a transposition of the result of the combn () function.
I thought about using the bigmemory package to create a file with big.matrix support, so I can assign the results to the combn () function. I can create a pre-allocated large matrix:
library(bigmemory) x <- as.character(1:1344) combos <- 403716544 test <- filebacked.big.matrix(nrow = combos, ncol = 3, init = 0, backingfile = "test.matrix")
But when I try to highlight the values ββof test <- combn(x, 3) , I still get the same thing: Error: cannot allocate vector of size 9.0 Gb
I even tried to achieve the result of combn(x,3) , but I think that since the combn () function returns an error, the big.matrix function also does not work.
test <- as.big.matrix(matrix(combn(x, 3)), backingfile = "abc") Error: cannot allocate vector of size 9.0 Gb Error in as.big.matrix(matrix(combn(x, 3)), backingfile = "abc") : error in evaluating the argument 'x' in selecting a method for function 'as.big.matrix'
Is there a way to combine these two functions together to get what I need? Are there other ways to achieve this? Thanks.