5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

lambdaR「俺もいるぜ」

Last updated at Posted at 2015-11-26

うさぎさんのこの記事で、purrrrlist を比較しているわけですが、

この程度のリスト操作なら lambdaR でもできます。

R
packages <- list(
  list(name = 'dplyr', star = 979L, maintainer = 'hadley' , authors = c('hadley', 'romain')),
  list(name = 'ggplot2', star = 1546L, maintainer = 'hadley' , authors = c('hadley')),
  list(name = 'knitr', star = 1047L, maintainer = 'yihui' , authors = c('yihui', 'hadley', '...and all'))
)

# パッケージのロード
library(lambdaR)
library(magrittr)
library(pipeR)

# 属性の選択
packages %>% Map_(x: x$name)
packages %>% Map_(x: list(maintainer=x$maintainer, star=x$star))

# ラムダ式
nums <- c(a = 3, b = 2, c = 1)
nums %>% Map_(x: x + 1)
nums %>% Map_(._ + 1)

nums %>% list(seq_along(.)) %>% Map2_(x, i: i)
nums %>% list(names(.)) %>% Map2_(x, name: paste0("Name: ", name))

# 属性の追加、変更
packages %>% Map_(x: list(star=x$star, had="hadley" %in% x$authors))

# 結果の型の変更
packages %>% Mapv_(x: x$star)
packages %>% Map_(x: data.frame(name=x$name, star=x$star)) %>% Reduce_(rbind)

# 関数の適用
packages %>>% (~ Map_(., x: cat(x$name, ":", x$star, "\n")))

# レコードの選択
packages %>% Filter_(x: x$star >= 1500)
packages %>% Filter_(x: "yihui" %in% x$authors)

Enjoy!

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?