Skip to content

Instantly share code, notes, and snippets.

fun is_older (day1 : int*int*int, day2 : int*int*int) =
if (#1 day1) < (#1 day2)
then true
else if (((#2 day1) < (#2 day2)) andalso ((#1 day1) = (#1 day2)))
then true
else if (((#3 day1) < (#3 day2)) andalso ((#2 day1) = (#2 day2)) andalso ((#1 day1) = (#1 day2)))
then true
else false
@timmyshen
timmyshen / complete.R
Created October 7, 2013 18:25
Write a function that reads a directory full of files and reports the number of completely observed cases in each data file. The function should return a data frame where the first column is the name of the file and the second column is the number of complete cases.
complete <- function(directory, id = 1:332) {
## 'directory' is a character vector of length 1 indicating
## the location of the CSV files
## 'id' is an integer vector indicating the monitor ID numbers
## to be used
## Return a data frame of the form:
## id nobs
## 1 117
---
name: ggplotly
layout: post
title: Make your ggplots shareable, collaborative, and with D3
date: 2014-04-17
author: Matt Sundquist
authorurl: https://plot.ly/team
tags:
- R
- API
@timmyshen
timmyshen / best.R
Created October 8, 2013 21:51
Write a function called best that take two arguments: the 2-character abbreviated name of a state and an outcome name. The function reads the outcome-of-care-measures.csv le and returns a character vector with the name of the hospital that has the best (i.e. lowest) 30-day mortality for the specied outcome in that state. The hospital name is the…
best <- function(state, outcome) {
data <- read.csv(file='outcome-of-care-measures.csv', colClasses = 'character')
if(!any(state == data$State)) {
stop('invalid state')
}
if(outcome == 'heart attack') {
i <- 11
.DS_STORE
@timmyshen
timmyshen / springer-free-maths-books.md
Created December 29, 2015 23:23 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of books available for free, here are the direct links
@timmyshen
timmyshen / NBA_stats_mining.py
Created December 27, 2015 16:30 — forked from tonyromarock/NBA_stats_mining.py
Scrapping NBA player stats from stats.nba.com
import requests
import csv
import sys
# get me all active players
url_allPlayers = ("http://stats.nba.com/stats/commonallplayers?IsOnlyCurrentSeason"
"=0&LeagueID=00&Season=2015-16")
#request url and parse the JSON
@timmyshen
timmyshen / number_before_reaching_sum.sml
Last active August 16, 2018 14:31
Write a function number_before_reaching_sum that takes an int called sum, which you can assume is positive, and an int list, which you can assume contains all positive numbers, and returns an int. You should return an int n such that the rst n elements of the list add to less than sum, but the rst n + 1 elements of the list add to sum or more. A…
fun number_before_reaching_sum (sum : int, xs : int list) =
if null xs then 0
(*else if null (tl xs) then 1*)
else if hd xs > sum then 0
else
let fun helper (i : int, partial_sum : int, tl_xs : int list) =
if partial_sum < 0 then i
else
helper(i + 1, partial_sum - hd tl_xs, tl tl_xs)
in
@timmyshen
timmyshen / rankall.R
Created October 9, 2013 18:04
Write a function called rankall that takes two arguments: an outcome name (outcome) and a hospital rank- ing (num). The function reads the outcome-of-care-measures.csv le and returns a 2-column data frame containing the hospital in each state that has the ranking specied in num. For example the function call rankall("heart attack", "best") would…
rankall <- function(outcome, num = "best") {
data <- read.csv(file="outcome-of-care-measures.csv", colClasses = 'character')
if(outcome == 'heart attack') {
i <- 11
}
else if(outcome == 'heart failure') {
i <- 17
}
else if(outcome == 'pneumonia') {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.