Can MATLAB read 'R' data files (*.Rda) directly?
60 ビュー (過去 30 日間)
古いコメントを表示
If so, what is the appropriate function?
0 件のコメント
回答 (2 件)
Peter
2023 年 6 月 9 日
If you have Python installed on your system, you can use use the Matlab python call functionality to read in such R files.
Firstly, ensure that you have installed the Python package pyreadr onto your system; this package reads/writes R RData and Rds files into/from pandas data frames, and does not require R to have been installed, not any other external dependencies installed.
Then you can load in matlab via the command:
dict = py.pyreadr.read_r(<path to rda file>);
As it stands the variable "dict" will be a Python OrderedDict, so to use data it contains you need to create a matlab array as follows:
result=double(dict{<key>}.values);
where <key> is the string defining which key of the pandas frame dict you wish to extract.
If in doubt, check which keys the imported panda frame has by running the command:
dict.keys()
Once you have found the key of interest, you may further check the complete properties of the data stored under this key by running the command:
dict{<key>}
0 件のコメント
Pierre Benoit
2014 年 9 月 17 日
編集済み: Pierre Benoit
2014 年 9 月 17 日
2 件のコメント
Andrew
2020 年 9 月 22 日
Now in 2020 with R studio 1.1.456, the 'write' function croaked with a mysterious "Error in cat...argument 1 (type 'list') cannot be handled by cat" error, but:
write.csv(variable,"filename");
worked just fine.
参考
カテゴリ
Help Center および File Exchange で Call Python from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!