Skip to content

Instantly share code, notes, and snippets.

Selva Prabhakaran selva86

Block or report user

Report or block selva86

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View 6_3_Dataframes.R
country <- c("France", "Germany", "Greece", "Italy", "Portugal", "Spain") # Countries
gdp_growth <- c(1.3, 0.3, 1.9, 0.3, NA, 2) # GDP growth
mkt_type <- factor(c("High", "High", "Low", "Medium", "Low", "Medium")) # Categories
df <- data.frame(country = country,
gdp_growth = gdp_growth,
market_typ = mkt_type,
stringsAsFactors = F)
View 6_2_Dataframes2.R
country <- c("France", "Germany", "Greece",
"Italy", "Portugal", "Spain", 'Spain') # Countries
gdp_growth <- c(1.3, 0.3, 1.9, 0.3, NA, 2, 0) # GDP growth
mkt_type <- factor(c("High", "High", "Low", "Medium", "Low", "Medium", 'Low')) # Categories
df <- data.frame(country = country,
gdp_grwth = gdp_growth,
market_typ = mkt_type,
stringsAsFactors = F)
df <- rbind(df, df, df, df)
View 6_challenges.R
country <- c("France", "Germany", "Greece", "Italy", "Portugal", "Spain") # Countries
gdp_growth <- c(1.3, 0.3, 1.9, 0.3, NA, 2) # GDP growth
mkt_type <- factor(c("High", "High", "Low", "Medium", "Low", "Medium")) # Categories
df <- data.frame(country = country,
gdp_grwth = gdp_growth,
market_typ = mkt_type,
stringsAsFactors = F)
View 5_1_Lists.R
# 1. From the list m below, get the number of page likes on the 10th day of the month
reviews <- c("spongy burgers", "hot and good","crispier than expected",
"hard to chew", "too large to chew", "takes time", "filling",
"unhealthy but delicious" )
set.seed(100)
pages <- 1:100
page_likes <- round(runif(30,1000,8000),0)
m <- list(reviews,pages,page_likes)
View 4_2_SetOperations_Challenge.R
m1 <- c(7, 4, 4, 14, 8, 14, 8, 1, 4, 1, 13, 5, 12, 13, 11, 5, 15, 1, 7, 4, 8, 4)
m2 <- c(17, 18, 7, 6, 20, 9, 20, 14, 5, 12, 15, 20, 8, 14, 14, 15, 12, 7, 20, 8, 8, 13, 8)
m1
m2
# Find items that are not common between m1 and m2
@selva86
selva86 / 4_5.R
Created Jan 14, 2020
Practice exercise for master R course
View 4_5.R
# 1. Direct assignment
system.time ({
item_id_hypo <- numeric()
for(i in 1:10000000){
item_id_hypo[i] <- i
}
item_id_hypo
})
@selva86
selva86 / 3_13.R
Created Dec 25, 2019
Mini challenge 13
View 3_13.R
set.seed(100)
clicks_28 <- round(runif (28,3000,4000))
sales_28 <- seq(from=100, to=150, length = 28)
visitors_28 <- runif (28, 1000, 1100)
discount_28 <- rep(c(1,1,1,0.5),7)
mrp <- 5 # maximum retail price
daily_max_revenue <- sales_28 * mrp # daily maximum revenue
daily_actual_revenue <- daily_max_revenue * discount_28 # revenue with discount
total_revenue <- sum(daily_actual_revenue) # total revenue
@selva86
selva86 / 3_12.R
Created Dec 23, 2019
Mini Challenge for R Course
View 3_12.R
# Mini Challenge Inputs
vans <- c(3,4,5,2,4,4,5)
boxes <- c(30,44,50,18,36,36,40)
View 03_Vectors_missingvalues_mc.R
# Pre-create a 'pizza_tc_score' vector with missing values
set.seed(100)
pizza_tc_score <- round(runif (1000,3,10))
pizza_tc_score [c(100,204,709,816,938)] = NA
@selva86
selva86 / ks_plot_example.R
Created Oct 5, 2017
Reproducible example for ks_plot
View ks_plot_example.R
library(InformationValue)
library(ggplot2)
# 1. Import dataset
trainData <- read.csv('https://raw.githubusercontent.com/selva86/datasets/master/breastcancer_training.csv')
testData <- read.csv('https://raw.githubusercontent.com/selva86/datasets/master/breastcancer_test.csv')
# 2. Build Logistic Model
logitmod <- glm(Class ~ Cl.thickness + Cell.size + Cell.shape, family = "binomial", data=trainData)
# 3. Predict on testData
You can’t perform that action at this time.