Skip to content

Instantly share code, notes, and snippets.

Rでデンドログラムのプロット

概要

  • データセットの作成(matrix,dist)
  • デンドログラム(樹形図)のプロット方法
  • グラフによる可視化

Rpubsにも投稿

@yuu-ito
yuu-ito / 0_reuse_code.js
Created March 20, 2014 03: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
# kaggle titanic
# https://www.kaggle.com/c/titanic-gettingStarted/data
t <- read.csv("../../Downloads/train.csv")
names(t)<-tolower(names(t))
idx<- sample(nrow(t),(nrow(t)*0.7))
t.tr <- t[ idx,]
t.te <- t[-idx,]
@yuu-ito
yuu-ito / pref_code.csv
Last active February 1, 2016 05:28
d<-read.csv("../../Desktop/pref_code.csv") http://ja.wikipedia.org/wiki/全国地方公共団体コード
PREF_CODE NAME REGION
01 北海道 北海道
02 青森県 東北
03 岩手県 東北
04 宮城県 東北
05 秋田県 東北
06 山形県 東北
07 福島県 東北
08 茨城県 関東
09 栃木県 関東
get_latlng_from_address<-function(zipcode){
require("rjson")
url.template<-"http://maps.googleapis.com/maps/api/geocode/json?language=ja&address"
url <- paste(url.template,zipcode,sep="=")
map_data <- fromJSON(paste(readLines(url), collapse=""))
if(map_data$status=="OK"){
address_info <- map_data$results[[1]]$address_components
location <- map_data$results[[1]]$geometry$location
res <- data.frame(
zipcode= zipcode,
@yuu-ito
yuu-ito / index.html
Last active September 1, 2017 10:33
vue.js( http://vuejs.org/ ) を試してみた。functionと打つ時間を計測するだけ。
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vue/0.12.16/vue.min.js"></script>
</head>
<body>
<h1>タイピングてすと:function</h1>
function + enter で計測
@yuu-ito
yuu-ito / 0_test.r
Last active August 29, 2015 14:05
RUnitのメモ
library('RUnit')
source('./mysum.r')
# refs
# - http://cran.r-project.org/web/packages/RUnit/RUnit.pdf
# - http://www.okada.jp.org/RWiki/?RUnit%20%A4%F2%BB%C8%A4%A6
test.mysum <- function(){
checkEqualsNumeric(mysum(1:10),55)
}
@yuu-ito
yuu-ito / bind.params.r
Last active August 29, 2015 14:05
文字列埋め込みっぽいもの。
bind.params<-function(txt.template,...){
require("dplyr")
loop.cnt <-
txt.template %>%
strsplit(.,"") %>%
unlist %in%
c('?') %>%
which %>%
length
res <- txt.template
import datetime
import calendar
def lastday_of_month(date):
y = date.year
m = date.month
last_d = calendar.monthrange(y, m)[1]
return date.replace(day=last_d)