samedi 11 septembre 2021

Sample in R a category with multiple levels and take a specific sample size from each category

I have the following dataset

library(gsheet)
data = gsheet2tbl("https://docs.google.com/spreadsheets/d/17JpiiY4L_9PrGELgEk_3dQgx_9qMG08T/edit?usp=sharing&ouid=109626011108852110510&rtpof=true&sd=true")

it contains 3 character variables (ID,GEAR,PORT).

Variable GEAR consists of 13 levels and i want to take a random sample of size n=30 in each category. The final dataset I want to contain all the samples in rows and the suited PORT.

I tried

data%>%
  group_by(GEAR)%>%
  sample_n(size=30,replace = TRUE)

but it didn't work.Any help ?




Aucun commentaire:

Enregistrer un commentaire