tidyverse / modelr

Helper functions for modelling
https://modelr.tidyverse.org
GNU General Public License v3.0
401 stars 65 forks source link

permute group_by #94

Closed jackdolgin closed 4 years ago

jackdolgin commented 5 years ago

Is it possible to do something along the following lines with modelr::permute, or if not I guess it's also a potential suggestion!

Using mtcars, would it be possible to first group_by, say, gear and carb value, and then only shuffle am values between rows with matching gear and carb values? that's as opposed to shuffling am values between all rows

I run into an error attempting the following (though that could also be due to the function I create)

df <- mtcars %>%
  group_by(gear, carb) %>% # no error once this line is commented out 
  modelr::permute(8, am)

df$perm %>% 
  map_df(function(x){
    x$data %>%
      mutate(am = x$idx)
  })

 # Error: Column `am` must be length 3 (the group size) or one, not 32 
hadley commented 4 years ago

This is out of scope for modelr, sorry. You might try tools in http://tidymodels.org/ instead.