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
  • 377,200
  • 20
  • 156
  • 213
gvajpai
  • 19
  • 1

0 Answers0