Please help me
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
Thanks in advance.
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)
Because you need to map to one lever lower, the columns are at level 2. So you can do:
Or:
Without the if one could do
You can try
lapply
:You are attempting to use
map_if()
over alist
ofdata.frames
. The predicate will be tested against eachdata.frame
, rather than each column of the data.frame e.g.And that is because...