更新时间:2021-08-27 21:36:40
我们可以遍历列表
,检查是否有任何$ 齿轮列中的c $ c>元素等于4,使用它来对
列表中的
名称
进行子集
We could loop through the list
, check whether there is any
element in 'gear' column that is equal to 4, use that to subset the names
of the list
names(mt_list)[sapply(mt_list, function(x) any(x$gear == 4))]
#[1] "4" "6"
或使用%in%
创建逻辑索引
names(mt_list)[sapply(mt_list, function(x) 4 %in% x$gear)]
#[1] "4" "6"