Skip to content

Instantly share code, notes, and snippets.

patternproject

Block or report user

Report or block patternproject

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 anti-join vs setdiff
# The main idea comes from this post:
# http://zevross.com/blog/2014/08/05/using-the-r-function-anti_join-to-find-unmatched-records/
# Setting up
df.1 <- data.frame(
state = rep(1:3, each=2),
country = rep(c("A","B"),3),
vals = rnorm(6)
)
@patternproject
patternproject / different_iteration.r
Created May 6, 2017
purrr - doing something different in first iteration
View different_iteration.r
# Helper Function
fn_downloadZip <- function(URL) {
myzip <- unz(URL, filename=basename(URL))
c.zip.name = "test.zip"
c.file.path = file.path(c.home.dir,c.data.dir,c.zip.name)
c.data.folder = file.path(c.home.dir,c.data.dir)
download.file(URL, destfile=c.file.path)
f.name = unzip(c.file.path, exdir=c.data.folder)
@patternproject
patternproject / gist:0a7ade8fa3d85453076d9bafc2087127
Created Apr 27, 2017
How to successively combine years and months using purrr
View gist:0a7ade8fa3d85453076d9bafc2087127
Hi,
-----------------------------------
PROBLEM STATEMENT
-----------------------------------
I want to generate URLS for each month for each year as follows:
[...]
https://s3.amazonaws.com/data/201611.csv.zip
https://s3.amazonaws.com/data/201612.csv.zip
View sessionizationInR.r
## `````````````````````````````````````````````
#### Read Me ####
## `````````````````````````````````````````````
## Trying to implement "sessionization" in R
## Details here:
## https://www.dataiku.com/learn/guide/code/reshaping_data/sessionization.html
## `````````````````````````````````````````````
## `````````````````````````````````````````````
#### Load Libraries ####
@patternproject
patternproject / .block
Last active Apr 9, 2017
d3.challenge1.2017Apr09
View .block
license: mit
View Secrets of Success.csv
Social Strata Reason Rate
Rich people good education, high qualification 28%
Middle class good education, high qualification 33%
Poor good education, high qualification 18%
Rich people cunning, cheating 11%
Middle class cunning, cheating 21%
Poor cunning, cheating 32%
Rich people abilities, talents 13%
Middle class abilities, talents 8%
Poor abilities, talents 7%
@patternproject
patternproject / pmap-v1.r
Last active Oct 17, 2016
df (df.nbl.win.2) contains country, yr1, y2 and yr3. Helper / Workhorse fn (fn_get_rank) takes country and year, returning rank. Using pmap I need to rename cols for proper mapping in pmap.
View pmap-v1.r
# -------------------
# HELPER FUNCTION
# -------------------
# fn to search rank
# INPUT: year (integer)
# OUTPUT: rank (integer)
# SRC:
# http://adv-r.had.co.nz/Functions.html
# https://cran.r-project.org/web/packages/ArgumentCheck/vignettes/ArgumentChecking.html
@patternproject
patternproject / saveListOfDfAsCsv.r
Created Sep 27, 2016
How to save a list of data frames
View saveListOfDfAsCsv.r
# list of all data frames
s.df = names(which(sapply(.GlobalEnv, is.data.frame)))
# list of data frames with .p. in their names
s.df.p = s.df[str_detect(s.df,regex("\\.p\\.",ignore_case = FALSE))]
# creating path
paths <- paste0(s.df.p,".1", ".csv")
# helper function
@patternproject
patternproject / glitchulate.py
Created Aug 27, 2016 — forked from hawkowl/glitchulate.py
Make your favourite images into glitched monstrosities! (Requires pillow from PyPI, Py2/3/pypy compatible)
View glitchulate.py
from __future__ import print_function
import sys
import random
from collections import deque
from PIL import Image
# THIS IS THE MAGIC VALUE THAT MAKES EVERYTHING GLITCHED
View expand in ggplot2
#### Load Data ####
df.winners = read.csv(
"winnersWithMean.csv",
header = TRUE,
stringsAsFactors = FALSE,
na.strings = c("", "NA")
)
# dput for df.winners
# at the end of the code
You can’t perform that action at this time.