メモ:dplyr 0.6.0は、select()するだけならtidyevalいらないっぽい
dplyrがもうCRANにsubmitされたという噂を聞いてNEWS.mdを読んでたら、こんなことが書かれていました。
select()
(and the internal functionselect_vars()
) now support column names in addition to column positions. As a result, expressions likeselect(mtcars, "cyl")
are now allowed.
説明の意味はあんまり理解できないんですが、こんな感じです。select()
とselect_()
の使い分けで悩んでいた時代はもう過去ですね。
メモ:カテゴリごとにデータフレーム単位で処理をしたいときはdplyr::do()とsplit() + purrr::map()のどちらが速い
追記(2017/07/26): コメント欄で指摘いただいたのでmap_df()
を使わないバージョン(f_split2()
)を追加しました。これはmap_df()
が遅いというより、split()
した数だけ新しくtibble()
をつくるのでその時間だろうなと推測しています。
ベクトルを引数に取る関数はgroup_by()
でいいわけですが、データフレームを引数に取るような関数はどうしますか?
メモ:WannaCryの送金データをblockchain .infoのAPIから取ってきてグラフを描きたい
追記(2017/05/21):
ツイートの主によるやり方解説ブログはこちら。
これを描きたい。が、元データはどこを見ればいいのかよくわからず調べた時のメモ。
続きを読むThe #wannacry attackers — if they can cash out before authorities find them — just topped $35K USD pic.twitter.com/UBQOrz1yJ0
— Боб Рудіс (@hrbrmstr) 2017年5月14日
メモ:stringr::str_locate_all()の結果をstringr::str_sub()に渡したいときはpurrr::map2()
例えば、適当な文字列からaで始まる単語を抜き出してみる(こんなことはstr_locate_all()
を使わなくてもできるけど、まあ例ということで)
library(stringr) library(purrr) x <- c("asymmetry between apple and banana", "aspiration after surgery") # \\p{Ll}はunicode property nameというやつらしい。 ptn <- "a[\\p{Ll}]+"続きを読む
メモ:Rでemojiを扱うにはどうすれば... part2
追記(2017/05/13): useBytes = TRUE
にした場合は、regmatches()
で抜き出すのはいけるけど、regmatches<-
で置換するのはエラーになる。うーん…
x <- "<img src='test.png' alt='🍉'>" m <- gregexpr("<\\s*[Ii][Mm][Gg]\\s+[Ss][Rr][Cc]\\s*=\\s*[\"']([^\"']+)[\"']", x, useBytes = TRUE) regmatches(x, m) #> [[1]] #> [1] "<img src='test.png'" #> regmatches(x, m) <- toupper(regmatches(x, m)) #> Error in nchar(u) : #> number of characters is not computable in "bytes" encoding, element 1
unicodeのことは分からないけど引き続きメモ。
続きを読むメモ:Rでemojiを扱うにはどうすれば...
こういう問題に悩まされていて、どうすればいいか調べる途中のメモ
具体的に言うとこのエラーをなんとかしたい。
# devtools::install_github("hadley/emo") wm <- emo::ji("watermelon") as.character(wm) #> [1] "\xf0\u009f\u008d\u0089" gregexpr(".", as.character(wm), perl = TRUE) #> Error in gregexpr(".", as.character(wm), perl = TRUE) : #> invalid input '拷' in 'utf8towcs'続きを読む