I'm kinda new to R and I'm trying to make a simple function that would take a sample of n observations from each of the groups in the df:
df <- data.frame(var1=c(rnorm(50,50,10)),b=letters[1:2])
The idea is to get 2 new df with a sample of n observations from eahc group (a or b).
I've tried this:
random_sample_groups <- function(aorb){
df_out <- df %>%
filter(group == "aorb") %>%
sample_n(10)
}
I don't know how to tell R that df_out are dataframes...
Your help will be appreacited, thanks!!