Matlab and R

55
D. Hiebele r,  Matlab /  R  Reference  1 MATLAB  R /  R  Reference June 24, 2014 David Hiebeler Dept. of Mathema tics and Stat istics University of Maine Orono, ME 04469-5752 http://www.m ath.umaine.edu/~hiebeler I wrote the rst version of this reference during Spring 2007, as I learned R while teaching my Modeling & Simula tio n cou rse at the Unive rsi ty of Mai ne. The course co ve rs population and epidemiologic al modeling, includ ing dete rminis tic and stochastic models in discrete and contin uous time, along with spatial models. Earlier versions of the course had used  Matlab. In Spring 2007, some biology graduate students in the class asked if they could use  R; I said “yes .” My colleag ue Bill Halteman wa s a grea t help as I frantically learned  R to stay ahead of the class. As I went along, I started building this reference for my own use. In the end, I was pleas ant ly surprise d that most things I do in  Matlab have fairly direct equivalents in  R. I was also inspired to write this after seeing the “ R for Octave Users” reference written by Robin Hankin, and have continued to add to the document. This reference is organized into general categories. There is also a  Matlab index and an  R index at the end, which should make it easy to look up a command you know in one of the languages and learn how to do it in the other (or if you’re trying to read code in whichever language is unfamiliar to you, allo w you to trans late back to the one you are more familiar with). The index entr ies refer to the item numbers in the rst column of the reference document, rather than page numbers. Any corrections, suggested improvements, or even just notication that the reference has been useful are appreciated. I hope all the time I spent on this will prove useful for others in addition to myself and my students. Note that sometimes I don’t necessarily do things in what you may consider the “best” way in a parti cular langu age. I often tried to do thing s in a similar way in both languages, and where possib le I’ve avoided the use of  Matlab  toolboxes or  R  packages which are not part of the core distributions. But if you believe you have a “better” way (either simpler, or more computationally ecient) to do something, feel free to let me know. For those transitioning from Matlab to R, you should check out the pracma package for R (“Practical Numerical Math Routines”) — it has more than 200 functions which emulate  Matlab functions, which you may nd very handy. Acknowledgements : Thanks to Jua n Da vid Ospina Arang o, Berry Boes sen koo l, Robert Bryce, Thomas Clerc, Alan Cobo-Lewis, Richard Cotton, Stephen Eglen, Andreas Handel, Niels Richard Hansen, Luke Hartigan, Roger Jeurissen, David Khabie-Zeitoune, Seungyeon Kim, Michael Kiparsky, Isaac Michaud, Andy Moody, Ben Morin, Lee Pang, Manas A. Pathak, Rachel Rier, Rune Schjellerup Philosof, Rachel Rier, William Simpson, David Winsemius, Corey Yanofsky, and Jian Ye for corrections and contributions. Permission is granted to make and distribute verbatim copies of this manual provided this permission notice is preserved on all copies. Permission is granted to copy and distribute modied versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice iden tical to this one. Permission is granted to copy and distribute translations of this manual into another language, un- der the above conditions for modied versions, except that this permission notice may be stated in a translation approved by the Free Software Foundation. Copyright  c 2014 David Hiebeler

Transcript of Matlab and R

Page 1: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 1/55

Page 2: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 2/55

Page 3: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 3/55

Page 4: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 4/55

Page 5: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 5/55

Page 6: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 6/55

Page 7: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 7/55

Page 8: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 8/55

Page 9: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 9/55

Page 10: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 10/55

Page 11: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 11/55

Page 12: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 12/55

Page 13: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 13/55

Page 14: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 14/55

Page 15: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 15/55

Page 16: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 16/55

Page 17: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 17/55

Page 18: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 18/55

Page 19: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 19/55

Page 20: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 20/55

Page 21: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 21/55

Page 22: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 22/55

Page 23: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 23/55

Page 24: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 24/55

Page 25: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 25/55

Page 26: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 26/55

Page 27: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 27/55

Page 28: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 28/55

Page 29: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 29/55

Page 30: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 30/55

Page 31: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 31/55

Page 32: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 32/55

Page 33: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 33/55

Page 34: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 34/55

Page 35: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 35/55

Page 36: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 36/55

Page 37: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 37/55

Page 38: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 38/55

Page 39: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 39/55

Page 40: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 40/55

Page 41: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 41/55

Page 42: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 42/55

Page 43: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 43/55

Page 44: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 44/55

Page 45: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 45/55

Page 46: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 46/55

Page 47: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 47/55

Page 48: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 48/55

Page 49: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 49/55

Page 50: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 50/55

Page 51: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 51/55

Page 52: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 52/55

Page 53: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 53/55

Page 54: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 54/55

Page 55: Matlab and R

8/10/2019 Matlab and R

http://slidepdf.com/reader/full/matlab-and-r 55/55