I have found that the following works
iris %>%
select(Sepal.Length) %>%
modelr::bootstrap(100) %>%
mutate(mean = map(strap, mean))
but the below does not
iris %>%
select(Sepal.Length) %>%
modelr::bootstrap(100) %>%
mutate(median = map(strap, median))
The only difference is that the second line of code uses the median.
The error I get is
Error in mutate_impl(.data, dots) : Evaluation error: unimplemented type 'list' in 'greater' .
The code looks like it's working, but if you
unnest
it, you're actually just getting a lot ofNA
s because you're trying to take themean
of aresample
object, which is a classed list with a reference to the data resampled and the indices for the particular resample. Taking the mean of such a list is not useful, so returningNA
with a warning is helpful behavior. To get the code to work, coerce the resample to a data frame, which you can operate upon as usual withinmap
's anonymous function.For a direct route, extract the data and take the mean, simplifying the list to a numeric vector with
map_dbl
:Translating this approach to
median
works fine:If you'd like both median and mean, you could repeatedly coerce the resample to a data frame, or store it in another column, but neither approach is very efficient. It's better to return a list of data frames with
map
that can beunnest
ed: