Skip to content

Instantly share code, notes, and snippets.

@fototo
fototo / mercy.R
Last active August 29, 2015 14:09 — forked from cpsievert/mercy.R
library(pitchRx)
library(dplyr)
library(mgcv)
# Establish a SQLite database connection
my_db <- src_sqlite("pitchRx.sqlite3")
# DISLCAIMER: this 'pitchfx.sqlite3' database was obtained using pitchRx version 1.2
# The code below probably won't work if you are using data collected from earlier versions or other methods
# Anyway, if you want to recreate this analysis, make sure you have pitchRx 1.2 or higher, then run:
require(igraph)
# generate a social graph
node_number = 100
g = barabasi.game(node_number) ; plot(g)
seeds_num = 1
set.seed(2014); diffusers = sample(V(g),seeds_num) ; diffusers
infected =list()
infected[[1]]= diffusers
library(mnormt)
mycols <- topo.colors(100,0.5)
xhat <- c(0.2, -0.2)
Sigma <- matrix(c(0.4, 0.3,
0.3, 0.45), ncol=2)
x1 <- seq(-2, 4,length=151)
x2 <- seq(-4, 2,length=151)
f <- function(x1,x2, mean=xhat, varcov=Sigma)
dmnorm(cbind(x1,x2), mean,varcov)
z <- outer(x1,x2, f)
This file has been truncated, but you can view the full file.
{
"metadata": {
"name": "",
"signature": "sha256:6eedb0030499d0d2d3e9771cf5de62fde633f5875dd94bf121c4f7f2dc2849c1"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@fototo
fototo / app.R
Last active August 29, 2015 14:14 — forked from hrbrmstr/app.R
library(shiny)
library(shinydashboard)
library(sparkline)
library(httr)
library(jsonlite)
library(data.table)
library(dplyr)
library(rvest)
library(magrittr)
library(XML)
@fototo
fototo / tufte
Last active August 29, 2015 14:14 — forked from abresler/tufte
library(dplyr)
library(tidyr)
library(magrittr)
library(ggplot2)
"http://academic.udayton.edu/kissock/http/Weather/gsod95-current/NYNEWYOR.txt" %>%
read.table() %>% data.frame %>% tbl_df -> data
names(data) <- c("month", "day", "year", "temp")
data %>%
group_by(year, month) %>%
#Script for scraping Chronicling America
import requests
import re
import csv
from bs4 import BeautifulSoup, SoupStrainer
import os
from time import sleep
from datetime import date, datetime, timedelta
#search_terms is a string of words separated by spaces.
library(KoNLP)
library(wordcloud)
library(plyr)
library(ggplot2)
library(scales)
tw <- read.delim('./data/NIS.csv', header=T, sep=',', stringsAsFactors=F)
tw.RT <- read.delim('./data/NIS_RT.csv', header=T, sep=',', stringsAsFactors=F)
tw.all <- read.delim('./data/NIS_withRT.csv', header=T, sep=',',
stringsAsFactors=F)
# -*- coding: utf-8 -*-
"""
Python: 3.4.2
author: dokenzy
date: 2015. 4. 21
license: MIT License
"""
import os
recipes = readLines('recipes combined.tsv')
# Once I read it into R, I have to get rid of the /t
# characters so that it's more acceptable to the tm package
recipes.new = apply(as.matrix(recipes), 1, function (x) gsub('\t',' ', x))
recipes.corpus = Corpus(VectorSource(recipes.new))
recipes.dtm = DocumentTermMatrix(recipes.corpus)