r programming basics

26
1

Upload: praveen-nair

Post on 22-Nov-2014

490 views

Category:

Data & Analytics


4 download

DESCRIPTION

R programming for beginners

TRANSCRIPT

Page 1: R programming basics

1

Page 2: R programming basics

2

Page 3: R programming basics

3

Page 4: R programming basics

Environment for statistical computing and graphics

Praveen Nairninethsense.com

Page 5: R programming basics

Data Science

Page 6: R programming basics

Statistics

CollectionOrganizationAnalysisInterpretationPresentation

Page 7: R programming basics

S

•1976 - 1998•Created by John Chambers•Developed by statisticians•At Bell Laboratories

Page 8: R programming basics

R

• Industry: Finance, Bio science, supply chain, Sports, Marketing, manufacturing, Health Care…•Used by: orion, bing, facebook, ford, google, twitter, firefox• 1993

Page 9: R programming basics

Developers

• Robert Gentleman

• Ross Ihaka

Page 10: R programming basics

R project

•http://r-project.org, CRAN•Collaboration of researchers in statistical computing•Open Source, Free Software• Interpreter•Over 3500 extension packages•Supported by large user network

Page 11: R programming basics

R console – RGui & Rterm

Page 12: R programming basics

Calculator

> 1+2[1] 3> 1+2*3[1] 7> (1+2)*3[1] 9> pi[1] 3.141593> sin(0)[1] 0> sin(1)[1] 0.841471

Page 13: R programming basics

Variables

> a = 100

> a + 5[1] 105

Page 14: R programming basics

Vector

> a = c(1,2,3,4)[1] 1 2 3 4> b = c(2,3,4,5)> a+b[1] 3 5 7 9>

Page 15: R programming basics

Sequences

> 1:10 [1] 1 2 3 4 5 6 7 8 9 10> a = 1:10> a [1] 1 2 3 4 5 6 7 8 9 10> a*2 [1] 2 4 6 8 10 12 14 16 18 20

Page 16: R programming basics

min, max, range

> a[1] 1 9 3 4> min(a)[1] 1> max(a)[1] 9> range(a)[1] 1 9

Page 17: R programming basics

sum, prod

> a = c(1,2,3,4)> sum(a)[1] 10> prod(a)[1] 24

Page 18: R programming basics

Strings

> a = "ORION"> a[1] "ORION"> substring(a,2,4)[1] "RIO“> nchar(a)[1] 5

Page 19: R programming basics

if-then/else

>if (a==50) date()[1] "Wed Jun 11 01:03:14 2014"

> a = 110> if (a > 100) "Greater than 100" else " Not greater than 100 "[1] "Greater than 100"> a = 50> if (a > 100) "Greater than 100" else “Not greater than 100"[1] "Not greater than 100"

Page 20: R programming basics

for loop

> a[1] 1 2 3 4> s = 0> for(i in a)+ s = s + i> s[1] 10

Page 21: R programming basics

switch

> i = 2> switch(i,"I","II","III")[1] "II"

Page 22: R programming basics

User functions

> f1 = function(r) 2 * pi * r

> f1(10)

[1] 62.83185

Page 23: R programming basics

Graphics

• Pie, Bar & Histograms

• Box-and-Whisker

• Scatter plot

• Time Series plots

• Surface plots

Page 24: R programming basics

plot

> x = 1:5> y = c(1.5, 2, 1, 3.2, 4.5)> plot(x,y)

Page 25: R programming basics

plot, lines, polygon, hist,…

> lines(x,y)> polygon(x,y)

Page 26: R programming basics

Demo time