変数の数 |
使う変数 |
リスト |
integerベクトル |
doubleベクトル |
characterベクトル |
logicalベクトル |
raw |
データフレーム |
無視(元の値) |
1個 |
. .x ..1 |
map |
map_int |
map_dbl |
map_chr |
map_lgl |
map_raw |
map_dfc, map_dfr |
walk |
2個 |
. .x .y ..1 ..2 |
map2 |
map2_dbl |
map2_dbl |
map2_chr |
map2_lgl |
map2_raw |
map2_dfc, map_dfr |
walk2 |
1個以上 |
. .x .y ..1 ..2 ..3 ..N |
pmap |
pmap_dbl |
pmap_dbl |
pmap_chr |
pmap_lgl |
pmap_raw |
pmap_dfc, map_dfr |
pwalk |
1個+インデックス |
. .x .y ..1 ..2 |
imap |
imap_dbl |
imap_dbl |
imap_chr |
imap_lgl |
imap_raw |
imap_dfc, map_dfr |
iwalk |
map
系関数
require(purrr)
1:5 %>% map(~.+2)
1:5 %>% map_dbl(~.+2)
1:5 %>% map_int(~.+2L)
1:5 %>% map_chr(~.+2)
1:5 %>% map_lgl(~.>2)
1:5 %>% map_raw(~as.raw(.+2))
1:5 %>% map_dfc(~set_names(data.frame(rep(., 5)), paste0("Col.", .)))
1:5 %>% map_dfr(~data.frame(a=., b=.+2))
set_names(1:5, letters[1:5]) %>% map(~.+2)
1:5 %>% walk(~print(.))
(1:5 %>% walk(~print(.)))
imap
系関数
require(purrr)
1:5 %>% imap(~paste0(.x+2, "-", .y))
1:5 %>% imap(~paste0(..1+2, "-", ..2))
set_names(1:5, LETTERS[1:5]) %>% imap(~paste0(.x+2, "-", .y))
1:5 %>% imap_dbl(~.x+.y)
1:5 %>% imap_int(~.x+.y)
1:5 %>% imap_chr(~.x+.y)
1:5 %>% imap_lgl(~.x+.y > 5)
1:5 %>% imap_raw(~as.raw(.x+.y))
set_names(1:5, LETTERS[1:5]) %>% imap_dfc(~set_names(data.frame(rep(., 5)), sprintf("Col%s", .y)))
set_names(1:5, LETTERS[1:5]) %>% imap_dfr(~data.frame(a=.x, b=.y))
1:5 %>% iwalk(~print(.x+.y))
(1:5 %>% iwalk(~print(.x+.y)))
map2
系関数
require(purrr)
map2(1:5, 11:15, -.x+.y)
map2_dbl(1:5, 11:15, ~.x+.y)
map2_int(1:5, 11:15, ~.x+.y)
map2_chr(1:5, 11:15, ~.x+.y)
map2_lgl(1:5, 11:15, ~.x+.y>15)
map2_raw(1:5, 11:15, ~as.raw(.x+.y))
map2_dfr(1:5, LETTERS[1:5], ~data.frame(A=.x, B=.y))
map2_dfc(1:5, LETTERS[1:5], ~set_names(data.frame(rep(.x, 5)), .y))
map2(set_names(1:5, letters[1:5]), set_names(11:15, LETTERS[1:5]), ~.x+.y)
map2_dbl(set_names(1:5, LETTERS[1:5]), 11:15, ~.x+.y)
walk2(1:5, LETTERS[1:5], ~print(paste0(.x, "-", .y)))