Skip to content

Instantly share code, notes, and snippets.

View jmcastagnetto's full-sized avatar
🇵🇪
Focusing

Jesus M. Castagnetto jmcastagnetto

🇵🇪
Focusing
View GitHub Profile
@jmcastagnetto
jmcastagnetto / sjt.xtab-bug.Rmd
Last active August 29, 2015 13:57
Code that illustrates the sj.xtab() bug when rendering to HTML with knitr (ref: https://github.com/sjPlot/devel/issues/1)
# bug in sjt.xtab()
```{r}
require(sjPlot)
set.seed(12345)
var1 <- as.factor(sample(c("ok", "not ok"), 1000, replace=TRUE, prob=c(0.2, 0.8)))
var2 <- as.factor(sample(c("foo", "bar", "boing", "kaboom", "plonk"), 1000, replace=TRUE))
var3 <- sample(2:20, 1000, replace=TRUE)
xtab1 <- sjt.xtab(var2, var3, var1, variableLabels=c("var2", "var3", "var1"),
showSummary=FALSE, showLegend=FALSE, no.output=TRUE)
@jmcastagnetto
jmcastagnetto / peru-presidents.Rmd
Last active August 29, 2015 14:00
A simple document showing the use of XML to get data from an HTML table, dplyr for data manipulation, lubridate for some simple date mangling, and ggplot2 and googleVis to generate nice charts (interactive in the case of googleVis)
---
title: "Analysis of the data on Presidents of Peru"
author: Jesus M. Castagnetto
output:
html_document:
toc: true
theme: readable
highlight: tango
---
# This is quick and dirty code that tries to reproduce the analysis and graph from the post:
# "Per capita consumption of mozzarella cheese (US) correlates with
# Civil engineering doctorates awarded (US)"
# URL: http://www.tylervigen.com/view_correlation?id=3890
# get the data from the article
library(XML)
url <- "http://www.tylervigen.com/view_correlation?id=3890"
tables <- readHTMLTable(url)
# we need table 3, minus a couple of extra columns
@jmcastagnetto
jmcastagnetto / README.md
Last active August 29, 2015 14:04
Script to use Pingdom's custom HTTP check, inspired by the one described in: http://jonsview.com/how-i-use-pingdoms-http-custom-feature

Script to be used with Pingdom's custom HTTP check.

Inspired by the code described in http://jonsview.com/how-i-use-pingdoms-http-custom-feature

Warning:

As of 20114-08-07, if you are using gzip compression in your server, creating a check pointing to an URL with the output of this script will fail, as the code been used by Pingdom does not yet grok compression.

The solution (at least for Apache), is to explicitly exclude from compression the path to the script in your server config, e.g.:

@jmcastagnetto
jmcastagnetto / repdata_project2.Rmd
Last active February 15, 2021 18:13
Source code for the analysis published in: http://rpubs.com/jesuscastagnetto/storms-impact
---
title: "The human health and financial impact of storms (1950-2011)"
author: "Jesus M. Castagnetto"
date: "2014-08-22"
output: html_document
---
**Course: Reproducible Research (Coursera), Assignment 2**
```{r}
@jmcastagnetto
jmcastagnetto / statinference-assignment-part1.Rmd
Last active April 28, 2019 14:12
Assignment for the "Statistical Inference" course (Coursera, August 2014)
---
title: "Part 1: Simulation using the exponential distribution"
author: "Jesus M. Castagnetto"
date: "2014-08-23""
output:
pdf_document:
highlight: zenburn
fontsize: 10pt
geometry: margin=0.8in
---
@jmcastagnetto
jmcastagnetto / kahansum.R
Last active November 26, 2015 05:56
Implementation in R of the Kahan summation algorithm
# Kahan summation
# ref: http://rosettacode.org/wiki/Kahan_summation
# Try using the task rules
# 1. Do all arithmetic in decimal to a precision of six digits.
options(digits=6)
# 2. Write a function/method/procedure/subroutine/... to perform Kahan summation
# on an ordered collection of numbers, (such as a list of numbers).
kahansum <- function(x) {
@jmcastagnetto
jmcastagnetto / kahansum.php
Last active August 29, 2015 14:11
Implementation in PHP of the Kahan summation algorithm
<?php
// ref: http://rosettacode.org/wiki/Kahan_summation
// 1. Do all arithmetic in decimal to a precision of six digits.
// PHP does not have a way of restricting overall precision
// 2. Write a function/method/procedure/subroutine/... to perform Kahan
// summation on an ordered collection of numbers, (such as a list of numbers). )
function kahansum($input) {
$sum = $c = 0;
@jmcastagnetto
jmcastagnetto / nist-beacon-response.R
Last active August 29, 2015 14:12
A simple and naive example of using the NIST Randomness Beacon in R (https://beacon.nist.gov/home)
require(RCurl)
require(XML)
# Let's make a special class
NISTBeaconResponse <- function (ts) {
if(!is.integer(ts) &
!inherits(ts, "POSIXct") &
!inherits(ts, "POSIXlt")) {
stop("We expected a unix timestamp as an integer or a POSIXct or POSIXlt value")
}
@jmcastagnetto
jmcastagnetto / freq-table.R
Last active July 11, 2019 17:44
Simple frequency table using dplyr
> library(dplyr)
> ft <- mtcars %>% group_by(gear) %>% summarise(freq=n())
> ft
Source: local data frame [3 x 2]
gear freq
1 3 15
2 4 12