Just a quick question: how to translate the dplyr function slice_sample into base R? Here is a toy dataset:
y <- rnorm(20)
x <- rnorm(20)
z <- rep(1:4, 5)
w <- rep(1:5, each=4)
dd <- data.frame(id=z,cluster=w,x=x,y=y)
Then I use slice_sample to randomly select 18 cases:
dd %>% slice_sample(n = 18) %>%
arrange(cluster)
How to translate the dplyr code above into base R without using any packages? Many thanks!