This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------------- START: Who's the best allrounder in world cup cricket ---------------------- | |
# read country and corresponding color info | |
country.color <- read.csv("country-colors.txt", header=T, sep=",") | |
# plot high runs/game and high wkts/game of players who've played at least N games in world cup cricket history | |
data <- world.cup.player.record[world.cup.player.record$ODI.played > 10 & !is.na(world.cup.player.record$Wickets.Per.Game) & !is.na(world.cup.player.record$Runs.Per.Game) & world.cup.player.record$High.Score.Probability > 0 & world.cup.player.record$High.Wicket.Probability > 0 & world.cup.player.record$Wickets.Per.Game > 0.8 & world.cup.player.record$Runs.Per.Game > 20,][,c("Player", "Country", "Runs.Per.Game", "Wickets.Per.Game", "High.Score.Probability", "High.Wicket.Probability", "Total.Batting.Runs.Scored", "Total.Wickets")] | |
# merge with country.color to get bubble color | |
data <- merge(data, country.color, by="Country") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# world.cup.player.record is a pre-computed data frame of player records. | |
> colnames(world.cup.player.record) | |
"Player", "Country", "ODI.played", "Total.Batting.Runs.Scored", "Total.Balls.Faced", "Total.Fours", "Total.Sixes", "Centuries", "Fifties", "Wins.When.Scored.Fifties", "Wins.When.Scored.Centuries", "High.Score.Probability", "Total.Wickets", "Total.Bowling.Runs.Given", Total.Overs.Bowled", "Total.Maidens", "Runs.Per.Game", "High.Wicket.Probability", "Economy" , "Five.Wicket.Hauls", "Three.Wicket.Hauls", "Wins.When.Three.Wicket.Hauls", "Wins.When.Five.Wicket.Hauls" | |
> country.color | |
country.color | |
Country Color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DATA | |
tendulkar <- structure(list(A = c(1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010), B = c(215, 373, 78, 419, 640, 700, 58, 623, 1000, 647, 1088, 575, 1003, 1392, 153, 915, 444, 267, 776, 1063, 541, 1003), C = c(35.83, 37.3, 19.5, 38.09, 71.11, 63.64, 14.5, 41.53, 58.82, 71.89, 57.26, 57.5, 55.72, 53.54, 17, 61, 44.4, 22.25, 48.5, 42.52, 60.11, 77.15)), .Names = c("Year", "Total.Runs.In.Year", "Runs.Per.Match.In.Year"), class = "data.frame", row.names = c(NA, -22L)) | |
ponting <- structure(list(A = c(1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010), B = c(NA, NA, NA, NA, NA, NA, 167, 163, 497, 382, 883, 318, 772, 1064, 1503, 697, 1444, 1333, 192, 1182, 853, 551), C = c(NA, NA, NA, NA, NA, NA, 83.5, 20.38, 45.18, 27.29, 51.94, 45.43, 32.17, 66.5, 83.5, 36.68, 55.54, 74.06, 32, 47.28, 37.09, 42.38)), .Names = c("Year", "Total.Runs.In.Year", "Ru |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# VARIABLES IN R | |
# Assignment | |
x <- 7 | |
y <- 8 | |
# Using other variables | |
z <- sqrt(x*x + y*y) | |
# Printing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# USE R AS A CALCULATOR | |
# Comments (like this one) are indicated with a # in R | |
# Addition | |
1 + 2 | |
# Subtraction | |
3.2 - 1.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ATOMIC DATA TYPES IN R | |
# Character | |
first.name <- "Kirk" | |
# Integer | |
age <- 25 | |
# Numeric | |
hourly_wage <- 27.25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DATA STRUCTURES IN R | |
# Vector: a sequence of elements of same atomicity | |
# Vectors can be formed by using the concatenate function c() | |
alphabets <- c("a", "b", "c") | |
alphabets | |
numbers <- c(1, 2, 3) | |
numbers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# VECTOR OPERATIONS IN R | |
# Create vectors | |
age <- c(28, 19, 29, 81, 60, 55, 44, 23) | |
year <- 1990:1995 # notice the use of : operator for sequence function (seq) | |
five.ones <- rep(1, 5) # checkout the use of repeat function | |
# a vector of odd numbers between 1 and 100 | |
odd.numbers <- seq(1, 100, by=2) | |
?seq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# LOCAL HELP | |
# R offers great help articles with the install | |
# Just type ? and the function if you know the function name | |
?sqrt # Pay special attention to function definition and take a look at the examples | |
# Type ?? and your search keyword to search a keyword in R help documentation | |
??maximum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CURRICULUM FOR INTRODUCTION TO R (DRAFT) | |
Day 1: | |
a) Install R | |
b) Use R as a calculator | |
Day 2: | |
a) Getting help | |
b) Use variables in R | |
c) Understand atomic data types in R |
OlderNewer