mardi 21 juin 2022

R SQL: Is the Default Option Sampling WITH Replacement?

I want to sample a file WITH REPLACEMENT on a server using SQL with R:

Pretend that this file in the file I am trying to sample:

library(dplyr)
library(DBI)

con <- dbConnect(RSQLite::SQLite(), ":memory:")
dbWriteTable(con, "iris", iris)

I want to sample with replacement 30 rows where species = setosa and 30 rows where species = virginica. I used the following code to do this:

rbind(DBI::dbGetQuery(con, "SELECT * FROM iris WHERE (`Species` = 'setosa') ORDER BY RANDOM() LIMIT 30;"), DBI::dbGetQuery(con, "SELECT * FROM iris WHERE (`Species` = 'virginica') ORDER BY RANDOM() LIMIT 30;"))

However at this point, I am not sure if the random sampling being performed is WITH REPLACEMENT or WITHOUT REPLACEMENT.

  • Can someone please help me determine if the random sampling being performed is WITH REPLACEMENT or WITHOUT REPLACEMENT - and if it is being done WITHOUT REPLACEMENT, how can I change this so that its done WITH REPLACEMENT?

Thank you!




Aucun commentaire:

Enregistrer un commentaire