Upcoming SlideShare
×

Introduction to R

497 views

Published on

Background, provided with https://gist.github.com/Nimster/4757490 to explain R to programmers.

Published in: Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
497
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
6
0
Likes
0
Embeds 0
No embeds

No notes for slide

Introduction to R

1. 1. INTRODUCTION TO R Nimrod Priell, October 2012 Thursday, September 5, 13
2. 2. WHAT IS R? Thursday, September 5, 13
3. 3. WHAT IS R? What is C? General-purpose programming language How do you pick all pairs of researchers and managers in C? Thursday, September 5, 13
4. 4. WHAT IS R? What is C? General-purpose programming language How do you pick all pairs of researchers and managers in C?           char** researchers ... /* Lior, Nimrod, Gadi */           char** managers ... /* Eran, Gadi, Roi */           int i = 0           int j = 0           for (int i = 0; i < 3; i++) {                for (int j = 0; j < 3; j++) {                     if (strncmp(researchers[i], researchers[j], 30)) {                          ... // expand our list, blah blah headache Thursday, September 5, 13
5. 5. WHAT IS R? What is Python? General purpose scripting language How do you pick all pairs of researchers and managers in Python? Thursday, September 5, 13
6. 6. WHAT IS R? What is Python? General purpose scripting language How do you pick all pairs of researchers and managers in Python? [ (x, y) for x in [‘Gadi’,‘Nimrod’,‘Lior’] for y in [‘Gadi’, ‘Roi’, ‘Eran’] if x != y ] Thursday, September 5, 13
7. 7. WHAT IS R? What is Python? General purpose scripting language How do you multiply matrices in Python? Thursday, September 5, 13
8. 8. WHAT IS R? What is Python? General purpose scripting language How do you multiply matrices in Python? def  matrixmult  (A,  B):        C  =  [[0  for  row  in  range(len(A))]  for  col  in  range(len(B[0]))]        for  i  in  range(len(A)):                for  j  in  range(len(B[0])):                        for  k  in  range(len(B)):                                C[i][j]  +=  A[i][k]*B[k][j]        return  C Thursday, September 5, 13
9. 9. WHAT IS R? What is Python? General purpose scripting language How do you multiply matrices in Python? import  numpy  as  np x  =  np.arange(9).reshape((3,3)) y  =  np.arange(3) print  np.dot(x,y) x.T.dot(A.T).dot(A.inverse()).dot(x) Thursday, September 5, 13
10. 10. WHAT IS R? What is Matlab? Algebraic programming language How do you multiply matrices in Matlab? A = [ 1 2 3;         4 5 6;         7 8 9 ] b = [ 6 4 -1 ] A’ * b’ * b / A Thursday, September 5, 13
11. 11. WHAT IS R? Incidentally, what is APL? (“A Programming Language”)  life←{↑1 ⍵∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵} (Conway's game of life in APL) Thursday, September 5, 13
12. 12. WHAT IS R? Statistical programming language Interpreted, Object Oriented, Functional First-class data-sets, plotting and models. cov(data\$Income[data\$Gender == ‘M’ & data\$country %in% c(‘uk’,’us’,’il’)], data\$LifeExp[data\$Gender == ‘F’ & data\$Age > 14]) lm(data, Income ~ Gender + Age) predict(model, data) Thursday, September 5, 13
13. 13. WHY R? Alternatives: Stata, SPSS, SAS, Excel R is Free and Open Source Packages for time-series, machine learning, biological simulation, computer vision, GPS, MapReduce, animation, optimization, graph analysis, reading any kind of data format, weather prediction, ... academia contributing packages http://cran.r- project.org/web/ packages/ Thursday, September 5, 13
14. 14. WHY R? R has Reproducible Research Excel: Click death Demo #1 Thursday, September 5, 13
15. 15. WHY R? R is a general purpose programming language Thursday, September 5, 13
16. 16. WHY R? R is a general purpose programming language Thursday, September 5, 13
17. 17. WHY R? R is a general purpose programming language Thursday, September 5, 13
18. 18. WHY R? R is a general purpose programming language Other alternatives are very specific: Weka, Orange, etc. Thursday, September 5, 13
19. 19. R DEMO The DataFrame IO Statistics & Models Plotting Remote RStudio https://gist.github.com/2838511 Thursday, September 5, 13
20. 20. WHY NOT R? Terribly slow... ... But there’s RCPP, RHadoop and multicore Terrible OO support and very quirky language ... But that only bothers you if you write packages Thursday, September 5, 13