Skip to content

Instantly share code, notes, and snippets.

@ggg5269
Last active December 28, 2019 08:56
Show Gist options
  • Save ggg5269/c014225a958db9508e6a2a2e6cee50d4 to your computer and use it in GitHub Desktop.
Save ggg5269/c014225a958db9508e6a2a2e6cee50d4 to your computer and use it in GitHub Desktop.
my_sample <- function(data, n, replace = F)
{
if (!replace && length(data) < n)
{
stop("invalid")
}
else
{
if (replace == F)
{
return(data[order(runif(length(data)))][1:n])
}
else
{
temp <- NULL
for (i in 1:n)
{
temp <- append(temp, data[order(runif(length(data)))][1])
}
return(temp)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment