DRYな備忘録

Don't Repeat Yourself.

r

Rで定数回数の繰り返し処理

r

いつも忘れてrange?とかやってる。ちがう。seqとsapply。 R: Sequence Generation Shifting sands: Using apply, sapply, lapply in R > sapply(seq(0,7), function(i) { 2 ^ i }) [1] 1 2 4 8 16 32 64 128 DRY

Rのplotで複数の関数を線で描画する

r

fun1 <- function(x) { (x + 2) * (x - 4) } fun2 <- function(x) { (x + 1) * (x - 6) } v <- seq(-4, 8) plot(v, fun1(v), type="l", col="red") lines(v, fun2(v), col="blue")

Rの日付・時間のパースと、時間差分の計算

r

# Datetime文字列のパース > t1 <- strptime("May 11 08:42:20", format = "%b %d %H:%M:%S" 1. ) > t2 <- strptime("May 11 08:47:23", format = "%b %d %H:%M:%S") # 時間の差分 > t2 - t1 Time difference of 5.05 mins # 秒でくれ > as.numeric(t2 - t1,…

R(とPython)で平均値、中央値、分散、標準偏差を求める

r

Rやりはじめた。 otiai10.hatenablog.com 勉強 平均値: 全要素の合計を要素数で割ったもの。重心。集合の代表値のひとつ。 (1/n) * Σx(k) 中央値: 全要素を小さい順にならべて真ん中の値そのもの。集合の代表値のひとつ。 x([n/2]) 分散: 各要素の平均値との…

はじめてのR

r

インストール R: The R Project for Statistical Computing % brew install r % R R version 3.5.0 (2018-04-23) -- "Joy in Playing" Copyright (C) 2018 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin16.7.0 (64-bit) R は、…