Skip to content

Instantly share code, notes, and snippets.

View azadag's full-sized avatar

Azad Amir-Ghassemi azadag

  • Los Angeles
View GitHub Profile
@azadag
azadag / PUMS weight example
Last active August 29, 2015 14:01
PERWT pums data...
## read in pums data (here to a dataframe called "b" ##
library(data.table)
dfMa<-data.frame(b$INDb,b$OCC1990b,b$pwmetro,b$perwt) ## toggle detailed
colnames(dfa) <- c("IND", "OCC", "PWMETRO","PERWT")
###build cross matrix using data.table #####
#### Convert data frame to Data Table
dtaa <- data.table(dfMa,key="IND,OCC,PWMETRO")

Bookmarklet to Post to Slack


Please note that this has a little problem: It posts the links as Slack Bot and not as yourself. You could add your name to the message but doesn't look right.


I've created a little bookmarklet that posts the url of the current webpage to a Slack channel. You have to set your token and the channel name manually but it's all fun and profit from there.

@azadag
azadag / MF-starts-ca.csv
Created April 7, 2015 13:43
Multi-family permit starts for California
We can make this file beautiful and searchable if this error is corrected: It looks like row 6 should actually have 50 columns, instead of 1 in line 5.
Mon-Yr,CA*,Alameda,Amador,Butte,Contra Costa,Del Norte,El Dorado,Fresno,Glenn,Humboldt,Kern,Kings,Lake,Los Angeles,Madera,Marin,Mariposa,Mendocino,Merced,Monterey,Napa,Nevada,Orange,Placer,Plumas,Riverside,Sacramento,San Benito,San Bernardino,San Diego,San Francisco,San Joaquin,San Luis Obispo,San Mateo,Santa Barbara,Santa Clara,Santa Cruz,Shasta,Siskiyou,Solano,Sonoma,Stanislaus,Sutter,Tehama,Tulare,Tuolumne,Ventura,Yolo,Yuba
Jan-88,"4,438",38,0,2,14,0,17,188,0,2,36,0,0,2187,2,4,0,0,111,12,0,0,383,0,0,83,298,0,384,174,79,5,18,56,7,209,0,4,0,0,6,23,0,0,49,0,10,0,4
Feb-88,"6,423",332,2,44,84,0,3,124,0,14,82,2,3,2575,24,0,0,0,38,35,8,4,429,0,0,647,124,0,695,618,67,5,2,130,2,16,2,0,16,8,48,37,0,0,34,5,107,6,18
Mar-88,"6,960",69,0,0,162,0,42,14,0,4,36,0,0,2471,16,0,2,2,54,39,15,66,899,0,0,159,227,0,564,1530,98,0,31,6,22,105,34,0,0,0,165,31,0,5,22,2,19,2,29
Apr-88,"10,109",79,2,2,68,0,202,33,0,8,42,0,0,2351,24,86,0,12,12,42,4,0,2354,274,0,423,96,8,250,1619,253,75,24,83,4,736,6,23,3,428,229,162,0,5,3,4,23,14,0
May-
@azadag
azadag / 0_reuse_code.js
Created December 10, 2015 23:43
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@azadag
azadag / new_gist_file_0
Created December 11, 2015 00:24
R ggplot Gists
theme_set( theme_bw( base_family= "serif"))
theme_update( panel.grid.minor= theme_blank(),
panel.grid.major= theme_blank(),
panel.background= theme_blank(),
axis.title.x= theme_blank(),
axis.text.x= theme_text( family= "serif",
angle= 90, hjust= 1 ),
axis.text.x= theme_text( family= "serif"),
axis.title.y= theme_blank())
@azadag
azadag / ipums_learn.r
Last active April 10, 2018 18:39
basic ipums summarisation examples
install.packages('data.table', 'dplyr', 'plyr')
library(dplyr)
data_acs <- data.table::fread("./data/usa_00035.csv")
data_acs <- tbl_df(data_acs)
## make an example age dummy variable
data_acs$AGE_VAR <- ifelse(data_acs$AGE < 15, 1, 0)
data_acs$AGE_VAR <- ifelse(data_acs$AGE >= 24 & data_acs$AGE <= 36 , 2, data_acs$AGE_VAR)
data_acs$AGE_VAR <- ifelse(data_acs$AGE > 36 & data_acs$AGE <= 51 , 3, data_acs$AGE_VAR)
@azadag
azadag / venn_pie_chart.r
Last active April 10, 2018 18:39 — forked from sterding/venn_pie_chart.r
R script to generate multi-layer pie chart (or called it venn pieagram) to visualize the NGS reads distribution in different annotation regions
## data input (number of reads mapped to each category)
total=100
rRNA=5 # mapped to nuclear rRNA regions
mtRNA=7 # mapped to mitochondria genome
# for the rest of above, then we divide into different category, like http://www.biomedcentral.com/1741-7007/8/149 did.
intergenic=48
introns=12
exons=30
upstream=3
downstream=6
empdataCA4 <- lapply(split(empdataCA3, empdataCA3$reg), function(x) {
x.Date <- (c(CurrentYear, CurrentYear + 1, CurrentYear + 2, CurrentYear + 3, CurrentYear +4 ,CurrentYear +5))
val <- as.ts(na.approx(zoo(x = c(x$Pct[1],NA,NA,NA,NA,x$Pct[2]), x.Date)))
val2 <-predict(td(val~1, to='quarterly', method='denton-cholette', conversion = "last"))
# change the options for interpolation as needed
data.frame(yearQtr= as.yearqtr(time(val2)), test=val2)})
df.dplyr <- as.data.frame(bind_rows(empdataCA4, .id = "groups"))
df.dplyr0 <- as.data.frame(stringr::str_split_fixed(df.dplyr$groups, "_", n=2))
ggplot(data = storms, aes(x = pressure)) +
geom_density(fill = 'cyan', color = 'cyan') +
labs(title = 'The pressure variable is strongly left-skewed') +
theme(text = element_text(family = 'Gill Sans', color = "#444444")
,panel.background = element_rect(fill = '#444B5A')
,panel.grid.minor = element_line(color = '#4d5566')
,panel.grid.major = element_line(color = '#586174')
,plot.title = element_text(size = 24)
,axis.title = element_text(size = 18, color = '#555555')
,axis.title.y = element_text(vjust = .5, angle = 0)