Learning R and Teaching R

35
Learning R and Teaching R

description

 a brief tutorial to learning R an teaching R including navigating syntax, documentation and interfaces

Transcript of Learning R and Teaching R

Page 1: Learning R and Teaching R

Learning Rand Teaching R

Page 2: Learning R and Teaching R

TodayTitle: R Language and Analytics as a Profession

Agenda:

1 hour hands on R coding (beginner/intermediate level)

1 Hour talking on Analytics as a Profession

Speaker: Mr. Ajay Ohri

Venue: Room No: 511, Department of Management studies (DMS), Vishwakarma Bhawan, IIT Delhi – 110016

Date & Time: 14 June 2014, Saturday 14.30 – 16:30 Hrs

Directions to Reach the Venue:

Option A: You need to get down at Malviya Nagar/Hauz Khas Metro station and ask auto to take you just near Katwariya Sarai.

Option B: Get down at Hauz Khas Metro Station. Take Bus (511 or 511A or Battery PoweredRickshaw to reach to Sanskrit Vidya peeth (near Katwaiya Sarai ).

Or Take Bus 764 and get down at IIT Hostel Gate. Walk a bit to reach DMS.

PLEASE NOTE-

DMS or IIT Delhi has no role in organizing this event.

Page 3: Learning R and Teaching R

New Delhi R Meetuphttp://www.meetup.com/New-Delhi-R-UseR-Group/298 members2 YearsSponsored

Non Commercial Group Only

Page 4: Learning R and Teaching R

Introduction● Learning R

○ R Console○ R Studio○ R GUIs○ R Cloud

● Teaching R

Page 5: Learning R and Teaching R

R from the Console● limited lines of code can submitted at a time● one graph can be viewed at a time● best for either beginners or really command line users● no syntax prompting● help is in a separate window

Page 6: Learning R and Teaching R

R Syntax- most important- # adding a hash or # comments out rest of sentencecomments make your code more readable

-?(keyword) looks for help on that keyword locally

-??(keyword) looks for help on that keyword in all the documentationAssignment

● objectname1=subset(df,df.name$var1 )

Page 7: Learning R and Teaching R

My first 25 R Commands What’s here?

● ls()● getwd()● setwd()● dir()● rm()

What’s in my object?● str()● class()● dim()● length()● names()● nrowl() # and ncol()

How do I select or change stuff● data.frame.name$variable● data.frame[row,column]● subset(df,df.name$var1 > X & df$var2 <Y | df$var3 ==” text”)

Function● function1=function(x,y,z){x^2+2x*y+(z/10)-23}

Math● log(x)● mean(x)● sd(x)● median(x)● exp(x)

Packages● install.package(“FOO”)● library(FOO)● update.package()

What can I do?● read.table()● write.table()● summary()● table()● plot()● hist()● boxplot()● library(Hmisc) describe()● library(Hmisc) summarize()

Page 8: Learning R and Teaching R
Page 9: Learning R and Teaching R
Page 10: Learning R and Teaching R

Install from CRAN

Page 11: Learning R and Teaching R

Downloading

Page 12: Learning R and Teaching R

Installation

Page 13: Learning R and Teaching R

Dependencies and Loading

Page 14: Learning R and Teaching R

Dependencies and Loading

Page 15: Learning R and Teaching R

My next 25 R Commands What’s missing?

● is.na()● na.omit()● na.rm=T

Operators● diff● lag● cumsum

Data Mining ● kmeans● arules::apriori ● tm::tm_map

References- http://www.statmethods.net/advstats/cluster.html

http://cran.r-project.org/web/packages/arulesViz/vignettes/arulesViz.pdf

http://cran.r-project.org/web/packages/tm/vignettes/tm.pdf

http://www.rdatamining.com/examples/association-rules

Modeling● cor(x)● lm(x)● vif(a)● outlierTest(a)

System ● system.time()● Sys.Date()● Sys.time()

What more can I do?● b=ajay[sample(nrow(ajay),replace=F,

size=0.05*nrow(ajay)),]

● png(“graph.png”) Write plot as png

file

● dev.off

Data Manipulation● as operator● substr● nchar● paste● difftime● strptime● lubridate::mdy● apply functions

Page 16: Learning R and Teaching R

My favorite 15 R Packages

Data Mining● tm● arulesViz● forecast

GUIs● rattle● Rcmdr

○ epack plugin○ KMggplot2 plugin

● Deducer

Visualization● ggplot2● ggmap

Data Handling● Dates- lubridate ● Analysis - Hmisc● Rcurl● XML● jsonlite

Page 17: Learning R and Teaching R

Some more R packages

slidifyhttp://slidify.org/

quantmodhttp://www.quantmod.com/

rocrhttp://rocr.bioinf.mpi-sb.mpg.de/

r chartshttp://rcharts.io/

Page 18: Learning R and Teaching R

My favorite R documentation

CRAN Viewshttp://cran.r-project.org/web/views/

R Documentationhttp://www.rdocumentation.org/

Inside Rhttp://www.inside-r.org/

Page 19: Learning R and Teaching R

R Documentation

Page 20: Learning R and Teaching R

Views

Page 21: Learning R and Teaching R

Stack Overflow

Page 22: Learning R and Teaching R

Stack Overflow - for R

Page 23: Learning R and Teaching R

Interfaces to R

R Studio -IDEGUIs - RCommander, rattle, DeducerOnline- R-fiddle, statace

Page 24: Learning R and Teaching R

Rattle GUI for Data Mining

Page 25: Learning R and Teaching R

RStudio

Page 26: Learning R and Teaching R

Rcmdr

Page 27: Learning R and Teaching R

Rcmdr

Page 28: Learning R and Teaching R

JGR

Page 29: Learning R and Teaching R

JGR

Page 30: Learning R and Teaching R

JGR with Deducer -Data Viz

Page 31: Learning R and Teaching R

R-Fiddle

Page 32: Learning R and Teaching R

Statace

Page 33: Learning R and Teaching R

Teaching RMultiple ways to do the same thing in R - Resolve CONFUSIONGUIs can be shortcut initially -Selective Introduction to PackagesWill need command line and ?help later on -Emphasizing documentation

Pace of learning to be as per audienceHuge Scope- hence should be kept pertinent to needs

Analytics is not StatisticsR is more than a computer language or syntaxProjects are the best teachers

Page 34: Learning R and Teaching R

R Project for Researchers

● creating packages for analytics relevant to industry ○ i.e telecom churn, rfm, ltv, retail

● any takers?

Page 35: Learning R and Teaching R

Thanks

Contact-

https://www.linkedin.com/in/ajayohriat ohri2007 @ gmail.com