【发布时间】:2017-01-12 15:39:48
【问题描述】:
我的列表看起来像这样:
what_i_have <- list(A = LETTERS[1:6], B = LETTERS[1:6], C = LETTERS[2:7])
我想根据列表元素的名称从每个向量中删除元素,所以我最终得到了这个:
what_i_want <- list(A = LETTERS[2:6], B = LETTERS[c(1, 3:6)], C = LETTERS[c(2,4:7)])
我可以对i_have_this 进行哪些操作才能访问i_want_this?
我已经通过使用purrr::map2(what_i_have, names(what_i_have), function(x, y) x == y) 获得了相同结构中的逻辑向量列表,但是我的大脑在尝试对what_i_have 进行子集化时超负荷。
我错过了什么?你能帮我吗?
tidyverse(或基本 R)解决方案的奖励积分。
library(testthat)
test_that("Turn what I have into what I want", {
expect_equal(what_i_have, what_i_want)
})
感谢您的帮助。
【问题讨论】: