Question

I have created a 300000 x 7 numeric matrix in R and I want to work with it in both R and Matlab. However, I'm not able to create a file well readeable for Matlab. When using the command save(), with file=xx.csv, it recognizes 5 columns instead; with extension .txt all data is opened in a single column instead. I have also tried with packages ff and ffdf to manage this big data (I guess the problem of R identifying rows and column when saving is related somehow to this), but I don't know how to save it in a readable format for Matlab afterwards.

An example of this dataset would be:

output <- matrix(runif(2100000, 1, 1000), ncol=7, nrow=300000)

Was it helpful?

Solution

If you want to work both with R and Matlab, and you have a matrix as big as yours, I'd suggest using the R.matlab package. The package provides methods readMat and writeMat. Both methods read/write the binary format that is understood by Matlab (and through R.matlab also by R).

Install the package by typing

install.packages("R.matlab")

Subsequently, don't forget to load the package, e.g. by

library(R.matlab)

The documentation of readMat and writeMat, accessible through ?readMat and ?writeMat, contains easy usage examples.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top