map_df() to produce an output that looks like `rbind`ed `lapply()`

You can use map_df(). Just need to pass in the names of hetro_var(m5) and name that list with itself.

mapdf_output <-
  names(hetro_var(m5)) %>%
  set_names(names(hetro_var(m5))) %>%
  map_df(function(i)sigma(m5)^2*abs(dat$x)^(2*hetro_var(m5)[i]))

assertthat::are_equal(mapdf_output, desired_output) # TRUE

It does seem a little funny that we have to name map inputs with their own values in some cases – I asked a question about this awhile back and it seems there’s no getting around the set_names() duplication.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top