Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Large Matrix in R [duplicate]

Tags:

r

matrix

How can I create a large matrix in R or how can I zip a large matrix into some object?

y <- matrix(rnorm(2e4*2e4),1:20000,1:20000)
Error: cannot allocate vector of size "..." Gb

How is it possible to allocate this matrix?

like image 371
And_R Avatar asked Dec 22 '25 12:12

And_R


2 Answers

I'm not sure why I'm giving this a serious answer but here goes...

1.I can install bigmemory just fine. Perhaps if you are having problems you should share the error message, your environment and OS, and then ask for help on that instead.

2.Perhaps this is just an example:

  y <- outer(1:20000,1:20000)
  Error: cannot allocate vector of size "..." Gb

but do you really want to do this? Couldn't you refactor your code to iterate/resample a smaller matrix many times or read the data a bit at a time, to wit...

3.Have you considered using RSQlite? It's super easy to install and especially now with the dplyr package is very user friendly.

like image 165
Stephen Henderson Avatar answered Dec 24 '25 03:12

Stephen Henderson


I am a huge fan of the bigmemory package and I am a Windows user. To use the package I first chose to stay with R 2.15 as it still has a functional Windows version of bigmemory package available on CRAN. For R 3.0 I had to compile that old version to work with my big matrices.

like image 27
Andrey Shabalin Avatar answered Dec 24 '25 04:12

Andrey Shabalin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!