将一个大的tibble分割成几个小的tibble,通过指定一系列的列可以由tidyverse
中的select
操作,我不知道如何使用map*
进行迭代并将它们存储在环境中,有什么好主意吗?
library(tidyverse)
#
my_tibble <- tibble(
col1 = rnorm(10),
col2 = runif(10),
col3 = letters[1:10],
col4 = sample(1:100, 10, replace = TRUE),
col5 = factor(rep(c("A", "B"), 5)),
col6 = LETTERS[1:10]
)
## assume the combination
grA <- c("col1", "col2")
grB <- c("col3", "col4")
grC <- c("col15", "col6")
cols_list <- list(grA, grB, grC)
## I can get one tibble by select:
my_tibble %>% select(cols_list[[1]])
## but how to use select with map* (rather the baseR) and store it into different objects?
my_tibble %>% map(~select(cols_list))
非常感谢!
2条答案
按热度按时间polkgigr1#
只需使用
lapply
,cu6pst1q2#
在底数R中,可以使用
split.default
: