r - Random extraction from a list with NO REPLACEMENT -
so wondering how extract randomly string list in r no replacement till list empty. write
sample(x, size=1, replace=false)
is not helping me, since string extracted more once before list gets empty.
kind regards
in every iteration 1 list element picked, , element value removed. if there 1 value left, list element removed.
x <- list(a = "bla", b = c("ble", "bla"), c = "bli") while (length(x) > 0) { s <- sample(x, size = 1) column <- x[[names(s)]] value <- sample(unlist(s, use.names = false), size = 1) list_element_without_value <- subset(column, column != value) x[[names(s)]] <- if (length(list_element_without_value) == 0) { null } else { list_element_without_value } }
Comments
Post a Comment