1

I'm trying to write my function to do stratified sampling from a dataframe

strSample<-function(x,grp,n) {
frac<-n/nrow(x)
x %>% group_by(grp) %>% sample_frac(.,frac)
}

where 'x' is dataframe, 'grp' is grouping variable, 'n' is number of samples to be taken

When I apply this to the 'iris' dataset using

strSample(iris,Species,15)

it gives me error "Error: Column grp is unknown "

What is wrong with my code?

Ronak Shah
  • 286,338
  • 16
  • 97
  • 143
gvajpai
  • 11
  • 1

0 Answers0