Lukas Püttmann    About    Research    Blog

Matlab struct to R dataframe

I just found the cool R package R.matlab which lets you easily transfer data saved in a Matlab struct to an R dataframe.

First run in Matlab:

% Create some data saved in a struct
data.first = rand(500, 1);
data.second = repmat({'abc'}, 500, 1);
save('./data.mat', 'data')

And then in R (see here):

matlabFile  <- readMat('data.mat')
varNames    <- names(matlabFile$data[,,1])
datList     <- matlabFile$data
datList     <- lapply(datList, unlist, use.names=FALSE)
data        <-
names(data) <- varNames