为什么map_if()在列表中不起作用 [英] why does map_if() not work within a list
本文介绍了为什么map_if()在列表中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮帮我
1)为什么map_if在列表中不起作用
2)有没有办法让它工作
3)如果没有,有什么替代方案
1) Why does map_if not work within a list
2) Is there a way to make it work
3) If not, what are the alternatives
提前致谢。
library(dplyr)
library(purrr)
cyl <- split(mtcars, mtcars$cyl)
# This works
map_if(mtcars, is.numeric, mean)
# This does not work
map_if(cyl, is.numeric, mean)
推荐答案
因为您需要映射到一个较低的杠杆,所以列位于2级。所以你可以执行:
Because you need to map to one lever lower, the columns are at level 2. So you can do:
map(cyl, ~map_if(., is.numeric, mean))
或:
map(cyl, map_if, is.numeric, mean)
如果没有,可以
at_depth(cyl, 2, mean)
这篇关于为什么map_if()在列表中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文