Skip to content

Instantly share code, notes, and snippets.

Assignments

Problem 1

Using the iris dataset as input, write a function that computes and returns the mean, std.dev and group size of Sepal.Length for each Species split by Petal.Length > CRITICAL_LENGTH where CRITICAL_LENGTH is the second input variable of you function. The output should be a data.frame and the column names should be meaningful. You must use split and apply (or sapply/lappy). No for-loops allowed.

require(data.table)
d <- data.table(foo=c(0,1,2,3,4),bar=c(5,6,7,8,9))
f1 <- function(a, b) {
(a**b)%%2
}
f2 <- function(d, a, b) {
as.logical(f1(d[,a,with=F],d[,b,with=F]))
vincent <- function(vec, N) {
qs <- quantile(vec, seq(0, 1, length.out=N))
v <- tapply(vec, findInterval(vec, qs), mean)
names(v) <- sapply(names(qs),function(x) as.numeric(sub("%","",x)))
v
}
# v <- vincent(rgamma(10000,1,1), 20)
require(ggplot2)
require(data.table)
require(parallel)
load_all("~/gazetools")
aTan <- function(x1,y1,x2,y2) {
y = (y2-y1)
x = (x2-x1)
a <- abs(atan(y/x)) * (180/pi)
if (y>=0 && x<0) {
.by <- "episode_number"
.call <- as.call(quote(order()))
.call[]] <- as.quoted(c(by,"-layer","parent","dist"))
setwd("~/cogback/cogback/Projects/Tetris/Rational Tetris/Analyses/Hope_2014")
require(lmer)
require(lmerTest)
fx <- read.table("allFixations3.dat",header=T)
# 1 intercept (mean fixation duration) for each subject, but each subject shares the same
# estimate for the affect of game_number, level and the their interaction
m1 <- lmer(fixation.duration~game_number*level+(1|id),fx)
import pickle
import os
from riotwatcher import RiotWatcher
with open (os.path.expanduser("~/.riot.key"), "r") as keyfile:
w = RiotWatcher(keyfile.read().replace('\n', ''))
champions = w.get_all_champions()
championsStatic = w.static_get_champion_list()
champNameLookup = {}
@RyanHope
RyanHope / LoL.R
Last active July 12, 2020 12:18
R Riot LoL
require(RCurl)
require(rjson)
require(stringr)
require(rgexf)
getRiotKey <- function() {
key <- getOption("riot.key")
if (is.null(key))
stop("getOption(\"riot.key\") returned NULL.")
key
#include "Rcpp.h"
using namespace std;
using namespace Rcpp;
/*
inline unsigned char saturate( float x )
{
return x > 255.0f ? 255
: x < 0.0f ? 0
// This file was generated by Rcpp::compileAttributes
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
#include <Rcpp.h>
using namespace Rcpp;
// GaussianSubsample
NumericMatrix GaussianSubsample(NumericMatrix img);
RcppExport SEXP gazetools_GaussianSubsample(SEXP imgSEXP) {