R and Octave/Matlab notes
As the Debian r-base package states: “S is the statistician’s Matlab and R is to S what Octave is to Matlab”. These notes document translations between R and Octave, and sometimes Matlab. (I do not have S and do not have access to Matlab all the time.)
R uses the nice platform-independent XDR binary format for saving its workspace. I'm sure one could read this into Octave with a bit of effort. However, is probably easier to use HDF5, which is not the native format of either R and Octave, but is supported out of the box by both. In R do:
Then in octave
works for simple data types, including matrices. Matlab should work too (it
has a function called
hdf5read), but I haven’t tried.
Sourcing a script file
In Octave/Matlab typing the name of a
.m-file runs the commands as
if typed into the current workspace. This has the same effect as
source("filename.r",local=T,print.eval=T) in R.
Wall clock time
Octave tic; ...; time_taken=toc R times=system.time((...)) time_taken=times
Octave start_time=cputime(); ...; cpu_time_taken=cputime()-start_time R times=system.time((...)) cpu_time_taken=sum(times[-3])
To record start and stop times in R, call
proc.time before and after
the code. The difference between these vectors is what
The performance of R and Octave should be in the same ball-park for many things, although I have not done a careful comparison.