Skip to content

Instantly share code, notes, and snippets.

View madilk's full-sized avatar

madilk

View GitHub Profile
@madilk
madilk / causalimpact.r
Created October 12, 2021 18:33
Causal impact package example for campaign data
options(scipen = 100)
install.packages("CausalImpact")
library(CausalImpact)
##YT video on running it in R : https://www.youtube.com/watch?v=H64ucBjgY6w
View(causaldata)
#convert data to time series
campaign_mkt <- ts(causaldata$sales)
non_campaign_mkt_1 <- ts(causaldata$sales_non_campaign_mkt_1)
non_campaign_mkt_2 <- ts(causaldata$sales_non_campaign_mkt_2)
@madilk
madilk / dplyr mutate to create column based on str_detect.md
Last active August 27, 2021 07:20
Tidyquery SQL queries for dataframes inside R programming

#Extract store names in dplyr via mutate

data_store<- data%>%
mutate(Store=
ifelse(str_detect(OrderId, "US"),"US",
ifelse(str_detect(OrderId, "CA"),"CA",
ifelse(str_detect(OrderId, "UK"),"UK",
"Other"))))
View(data_store)

@madilk
madilk / add missing dates and fill NAs
Last active August 24, 2021 19:43
dplyr - mutate , subset and group_by
#Padr package method
#https://statisticsglobe.com/insert-rows-for-missing-dates-in-r
#install.packages("padr")
library(padr)
offerdata_padr <- pad(offerdata)
View(offerdata_padr)
#https://www.statology.org/dplyr-replace-na-with-zero/
#Add rows for missing dates and replace NAs with zero
offerdata2<- offerdata%>%
complete(Date = seq.Date(min(Date), max(Date), by="day"))%>%
@madilk
madilk / modeltime r package for time series forecasts.r
Last active July 6, 2021 21:06
modeltime r package for time series forecasts - google analytics data
# R TIPS ----
# TIP 040 | Introduction to Modeltime: In Under 10-Minutes ----
#By Matt Dancho, modeltime package creator
#R Tips newsletter by Matt Dancho: https://mailchi.mp/business-science/r-tips-newsletter
# LIBRARIES ----
#installing packages from git
#install.packages("devtools")
library(devtools)
library(usethis)
@madilk
madilk / geom_mark_hull.r
Last active June 30, 2021 05:43
ggforce r package with google analytics data: geom_mark_hull
#creator of ggforce package: Thomas Lin Pedersen
#https://ggforce.data-imaginist.com/reference/geom_mark_hull.html
library(googleAnalyticsR)
ga_auth(json_file="C:\\location-of-your-json-file-folder\\service-key.json")
#update your view id
viewID <- 12345678
data <- google_analytics(
viewID,
date_range=c("2019-01-01","2021-06-28"),
@madilk
madilk / pyramid_chart in r prog.r
Created June 21, 2021 20:51
Pyramid chart in R using Google Analytics API plus demographic data [age and gender]
#source R script
#https://thomas-neitmann.github.io/ggcharts/reference/pyramid_chart.html
library(googleAnalyticsR)
#pull data from GA API
library(googleAnalyticsR)
#change location of json service key
ga_auth(json_file = "C:\\secret-folder\\service-key.json")
account_list$viewId
#change view id
viewID <- 12345678
@madilk
madilk / DataExplorer EDA R package.r
Last active June 10, 2021 15:22
DataExplorer package in R
#pull data from GA API
library(googleAnalyticsR)
#change location of json service key
ga_auth(json_file = "C:\\folder-where-your-service-creds-JSON-is-located\\json-service-key.json")
account_list$viewId
#change view id of
viewID <- 12345678
data <- google_analytics(
viewID,
date_range = c("2020-01-01","2021-06-09"),
@madilk
madilk / data studio - group content where page begins with - pattern.md
Last active June 2, 2021 18:30
Datastudio - Group content where page starts with - as pattern

CASE

WHEN REGEXP_MATCH(Page,"((?i).^/blog).") THEN "Blog"

WHEN REGEXP_MATCH(Page,"((?i).^/contact).") THEN "Contact"

ELSE "Other"

END

@madilk
madilk / arules market basket lift visualization in r plus shiny.r
Last active May 26, 2021 20:27
arules market basket lift visualization in r plus shiny
#https://github.com/mhahsler/arulesViz#standard-visualization
#install.packages("shiny")
library(shiny)
#install.packages("shinythemes")
library(shinythemes)
rules <- apriori(tr, parameter = list(support = 0.02, confidence = 0.02))
ruleExplorer(rules)
@madilk
madilk / arulesviz plotly for lift visualization
Last active May 26, 2021 20:01
Arules viz - Market Basket Analysis in R Prgramming
#install.packages("plotly")
library(plotly)
plot(rules,engine="plotly")