dimanche 30 mai 2021

Multiple Samples Without Replacement in R

I have a data set of roughly 20000 customers and some assorted indicator variables. I am trying to create 20 groups of 1000 unique customers. My original thought was to take 20 samples without replacement but I am finding it difficult to repeatedly sample. This is the code I initially thought about but it requires me to repeat this process 20 times which seems very clunky. Does anyone have thoughts about an easier way to create subsets of the data with no replacement.

set.seed(1)

sample1<-sample(fullindicators$customer_id,1000,replace=FALSE)

fullindicators$customer_id<-fullindicators$customerid[!(fullindicators$customer_id %in% sample1)]




Aucun commentaire:

Enregistrer un commentaire