Here, how I would like to do this using data.table
library(data.table) indx <- setDT(df)[, .I[sample(.N, 10, replace = TRUE)], by = type1]$V1 df[indx]
Or a simpler version would be
setDT(df)[, .SD[sample(.N, 10, replace = TRUE)], by = type1]
Basically, we are a selection (with a replacement - as you have less than 10 rows in each group) from the row indices inside each type1 group, and then a subset of the data at that index
Similarly dplyr you can do
library(dplyr) df %>% group_by(type1) %>% sample_n(10, replace = TRUE)
source share