This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Takes a json file describing chess games and produces a matrix with one row | |
# per turn showing how many pieces are left, one column per piece. | |
### Don't run this in R studio because it will take up twice the RAM | |
### as R will make copies instead of references. | |
library(jsonlite) | |
library(stringi) | |
# Path to your json file as produced by this script: https://gist.github.com/rasmusab/07f1823cb4bd0bc7352d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
year | births | deaths | clinic | |
---|---|---|---|---|
1841 | 3036 | 237 | clinic 1 | |
1842 | 3287 | 518 | clinic 1 | |
1843 | 3060 | 274 | clinic 1 | |
1844 | 3157 | 260 | clinic 1 | |
1845 | 3492 | 241 | clinic 1 | |
1846 | 4010 | 459 | clinic 1 | |
1841 | 2442 | 86 | clinic 2 | |
1842 | 2659 | 202 | clinic 2 | |
1843 | 2739 | 164 | clinic 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
date | births | deaths | |
---|---|---|---|
1841-01-01 | 254 | 37 | |
1841-02-01 | 239 | 18 | |
1841-03-01 | 277 | 12 | |
1841-04-01 | 255 | 4 | |
1841-05-01 | 255 | 2 | |
1841-06-01 | 200 | 10 | |
1841-07-01 | 190 | 16 | |
1841-08-01 | 222 | 3 | |
1841-09-01 | 213 | 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### An example of building a TensorFlow model from R using rPython ### | |
# For this script you need to | |
# 1. Have python 2.7 installed. | |
# 2. Install the rPython package in R. | |
# 3. Install Google's TensorFlow library as per these instructions: | |
# http://www.tensorflow.org/get_started/os_setup.md#binary_installation | |
### Here is how to setup and run a trivial TensorFlow model ### | |
# Load TensorFlow (I couldn't get this to work without setting sys.argv... ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
date | group | n_purchases | |
---|---|---|---|
2017-05-01 | 0 | 124 | |
2017-05-02 | 0 | 95 | |
2017-05-03 | 0 | 147 | |
2017-05-04 | 0 | 116 | |
2017-05-05 | 0 | 219 | |
2017-05-06 | 0 | 248 | |
2017-05-07 | 0 | 132 | |
2017-05-08 | 0 | 110 | |
2017-05-09 | 0 | 114 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A barely tested R script that takes a backgammon match in any format | |
# gnubg can read, analyzes the match and returns a data frame with the analysis | |
# It requires that gnubg is readily available on the command line. | |
library(tidyverse) | |
library(jsonlite) | |
library(glue) | |
analyze_bg_match <- function(match_fname, match_format = "auto") { | |
gnubg_analysis_fname = tempfile() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Converts the millionbase chess PGN database (http://www.top-5000.nl/pgn.htm) to json | |
# with one json dictionary per row. (That is, the resulting file is contain multiple json objects, | |
# not just one large). | |
import json | |
import chess.pgn # From python-chess https://github.com/niklasf/python-chess | |
pgn = open("millionbase-2.22.pgn") # Or where you have put it | |
fout = open('milionbase-2.22.json', 'w') # Or where you want it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 CLS | |
10 REM SETTING UP THE VARIABLES AND DATA | |
20 | |
30 REM NO OF PUPS PER DEN FROM A SAMPLE OF 16 WOLF DENS | |
40 DATA 5, 8, 7, 5, 3, 4, 3, 9, 5, 8, 5, 6, 5, 6, 4, 7 | |
50 | |
60 NDATA = 16 | |
70 NSAMPLES = 1000 | |
75 NBURNIN = 250 | |
80 NPARAMS = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
date | pageviews | |
---|---|---|
2015-01-01 | 13 | |
2015-01-02 | 27 | |
2015-01-03 | 56 | |
2015-01-04 | 18 | |
2015-01-05 | 18 | |
2015-01-06 | 8 | |
2015-01-07 | 19 | |
2015-01-08 | 32 | |
2015-01-09 | 45 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prior to the tutorial make sure that the script below runs without error on your R installation. | |
# You first need to install the follwoing packages: | |
# install.packages(c("rstanarm", "prophet", "CausalImpact")) | |
library(rstanarm) | |
library(prophet) | |
library(CausalImpact) | |
# This will test that rstanarm works | |
# Don't be alarmed if you get a warning about "divergent transitions " |