Skip to content

Instantly share code, notes, and snippets.

View kohske's full-sized avatar

kohske takahashi kohske

  • Ritsumeikan University
  • Osaka, Japan
  • X @kohske
View GitHub Profile
source('r3js.r')
obj <- r3js_new()
N <- 250
x <- rnorm(N, 0.5, 0.2)
y <- rnorm(N, 0.5, 0.2)
z <- rnorm(N, 0.5, 0.2)
obj <- r3js_add(obj, r3js_point(x, y, z))
install.packages("devtools", dep = TRUE)
library(devtools)
dev_mode()
install_github("r3js", "kohske")
library(r3js)
example(r3js_gen)
@kohske
kohske / sazae.r
Created March 25, 2012 17:14
sazae san no janken
d <- iconv(readLines("http://www.asahi-net.or.jp/~tk7m-ari/sazae_ichiran.html"), "sjis")
d <- strsplit(gsub("<BR>$", "", d[grepl("^第[0-9]+回", d)]), "\t")
d <- as.data.frame(do.call("rbind", d), stringsAsFactors = FALSE)
names(d) <- c("N", "D", "H")
d[d$N=="第7回", ]$D <- "91.12.01"
d <- transform(d,
N = gsub("[^0-9]", "", N),
D = as.Date(D, "%y.%m.%d"),
H = ifelse(grepl("グー", H), "グー",
ifelse(grepl("チョキ", H), "チョキ",
@kohske
kohske / nestedloop.r
Created March 31, 2012 03:01
Nested Loop in R
# nested loop creation
s <- (Reduce(function(a, b) substitute(`for`(i, j:3, x), list(i = as.name(letters[b]), j = `if`(b == 1, 1, as.name(letters[b-1])), x = a)), 4:1, quote(print(c(a, b, c, d)))))
@kohske
kohske / gist:2344367
Created April 9, 2012 15:49
source text for the qiita
(Rの)プロミス問題 その2。
http://qiita.com/items/660eac769fa1a82fbf42 の続き。
## Promiseとは
非常にざっくり言うと、プロミスとは「レシピと調理場を指定されたおっさん」です。
プロミスを作るということは、おっさんにレシピと調理場を教えといて、いつでも必要なときにご飯を出してもらえるように準備しといてもらいます。
おっさんは、「メシっ」って言われてら、調理場に走って行って、レシピを見て、料理を作ってくれます。
なお、おっさんは、料理は作ってくれるんですが、それを見せてくれるだけです。
@kohske
kohske / errorbars.r
Created April 30, 2012 14:04
error bar for within-subject design
library(reshape2)
library(ggplot2)
set.seed(42)
v1 <- rnorm(20, 0, 20)
v2 <- v1 + 0.1 + rnorm(20, 0, 0.1)
df1 <- melt(data.frame(v1, v2))
TT1 <- t.test(value ~ variable, data = df1, paired = TRUE)
v1 <- rnorm(20, 0, 10)
@kohske
kohske / mt19937ar_for_R.c
Created June 1, 2012 03:51
matlab's rand by R
/*
A C-program for MT19937, with initialization improved 2002/1/26.
Coded by Takuji Nishimura and Makoto Matsumoto.
Before using, initialize the state by using init_genrand(seed)
or init_by_array(init_key, key_length).
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
All rights reserved.
@kohske
kohske / demo01.Rmd
Created June 1, 2012 22:35
Rmd for slidify
```{r setup, echo = FALSE}
opts_knit$set(out.format = 'html')
opts_chunk$set(highlight = TRUE)
```
# Slidify
超簡単スライド作成
@kohske
@kohske
kohske / iris_demo.r
Created June 16, 2012 08:02
iris_demo for rstudio & notebook & rpubs
## レポート書きましょう。
# ライブラリ読み込み
library(plyr)
library(ggplot2)
library(reshape2)
library(grid)
# データ読み込み
data(iris)
@kohske
kohske / script.R
Created June 22, 2012 21:44
report generation by spin
#' # Rスクリプトからレポート生成
#' # `spin`ning in knitr package
#'
#' ### @kohske
#'
#' Rスクリプトはこちら
#' https://gist.github.com/gists/2975392
#'
#' ---
#'