Skip to content

Instantly share code, notes, and snippets.

View hrstt's full-sized avatar

sato hiroyuki hrstt

View GitHub Profile
@hrstt
hrstt / chisq.test.by.tidy.R
Last active November 29, 2019 01:36
for chisq.test, convert count data to matrix with tidyverse
library(tidyverse)
tidyToChisq <- function(data, col, row) {
return(
data %>% group_by_(col, row) %>%
summarise(count = n()) %>% spread(row, count, fill = 0) %>%
ungroup() %>% select(-starts_with(col)) %>% as.matrix() %>% chisq.test())
}
library("tidyverse")
library("dummies")
iris %>% select(Species) %>% dummy.data.frame(., c("Species"), sep="_")
@hrstt
hrstt / merge_each_excel_sheets.r
Created November 11, 2016 00:43
複数のExcelシートにデータがある場合にそれらを結合する(同一の列構成である前提)
install.packages("xlsx")
library("xlsx")
n <- 10
a <- list()
for(i in 1:n) {
a[[i]] <- read.xlsx("data.xlsx", sheetIndex=i, encoding="UTF-8", header = FALSE)
}
data <- do.call(rbind, a)
@hrstt
hrstt / summing_runif_is_instead_of_rnorm.R
Created November 11, 2016 00:38
一様分布の和の平均は正規分布の近似に使える(中心極限定理)
sum_runif <- function(x) {
a <- runif(n = 1000)
if (x <= 1) return(a)
else return(a + Recall(x-1))
}
hist(sum_runif(5))
hist(sum_runif(1))
hist(sum_runif(10))
@hrstt
hrstt / icd10list_NtoZ.tsv
Created October 18, 2016 05:04
ICD10 国際疾病分類第10版(2003年改訂) # ref: http://www.dis.h.u-tokyo.ac.jp/byomei/icd10/
We can't make this file beautiful and searchable because it's too large.
ICD10(except dot) ICD10 name order topcategory
N00 N00 急性腎炎症候群 14 尿路性器系の疾患
N000 N00.0 急性腎炎症候群,軽微糸球体変化 14 尿路性器系の疾患
N001 N00.1 急性腎炎症候群,巣状及び分節状糸球体変化 14 尿路性器系の疾患
N002 N00.2 急性腎炎症候群,びまん性膜性糸球体腎炎 14 尿路性器系の疾患
N003 N00.3 急性腎炎症候群,びまん性メザンギウム増殖性糸球体腎炎 14 尿路性器系の疾患
N004 N00.4 急性腎炎症候群,びまん性管内増殖性糸球体腎炎 14 尿路性器系の疾患
N005 N00.5 急性腎炎症候群,びまん性メザンギウム毛細管性糸球体腎炎 14 尿路性器系の疾患
N006 N00.6 急性腎炎症候群,デンスデポジット病 14 尿路性器系の疾患
N007 N00.7 急性腎炎症候群,びまん性半月体形成性糸球体腎炎 14 尿路性器系の疾患
@hrstt
hrstt / icd10list_AtoM.tsv
Last active October 18, 2016 05:38
ICD10 国際疾病分類第10版(2003年改訂) ref: http://www.dis.h.u-tokyo.ac.jp/byomei/icd10/
ICD10(except dot) ICD10 name order topcategory
A00 A00 コレラ 1 感染症および寄生虫症
A000 A00.0 コレラ菌によるコレラ 1 感染症および寄生虫症
A001 A00.1 エルトールコレラ菌によるコレラ 1 感染症および寄生虫症
A009 A00.9 コレラ,詳細不明 1 感染症および寄生虫症
A01 A01 腸チフス及びパラチフス 1 感染症および寄生虫症
A010 A01.0 腸チフス 1 感染症および寄生虫症
A011 A01.1 パラチフスA 1 感染症および寄生虫症
A012 A01.2 パラチフスB 1 感染症および寄生虫症
A013 A01.3 パラチフスC 1 感染症および寄生虫症
# ggplot2 をベースにしたペアプロットのサンプル
install.packages("GGally")
library(GGally)
airquality$Month <- as.factor(airquality$Month)
airquality <- airquality[, colnames(airquality) != "Day"]
ggpairs(na.omit(airquality), lower=list(continuous="smooth"), colour="Month", params=list(corSize=6,labelSize=10))
@hrstt
hrstt / 0_reuse_code.js
Created December 19, 2013 10:52
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@hrstt
hrstt / file0.txt
Created March 26, 2013 15:45
Ubuntu 12.10 にRiak 1.3.0 を用意する ref: http://qiita.com/items/263307d147806cc52ca1
$ sudo apt-get install build-essential libncurses5-dev openssl libssl-dev
$ wget http://erlang.org/download/otp_src_R15B01.tar.gz
$ tar zxvf otp_src_R15B01.tar.gz
$ cd otp_src_R15B01
$ ./configure && make && sudo make install
@hrstt
hrstt / add_event.sql
Created March 26, 2013 15:17
7つのデータベース 7つの世界 2章 PostgreSQL 2日目 ref: http://qiita.com/items/8a00a1eb47921ffa49a5
CREATE OR REPLACE FUNCTION add_event(title text, starts timestamp, ends timestamp, venue text, postal varchar(9), country char(2) )
RETURNS boolean AS $$
DECLARE
did_insert boolean := false;
found_cont integer;
the_venue_id integer;
BEGIN
SELECT venue_id INTO the_venue_id
FROM venues v