DRYな備忘録

Don't Repeat Yourself.

2018-05-01から1ヶ月間の記事一覧

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,…