Last active
December 28, 2019 08:56
-
-
Save ggg5269/c014225a958db9508e6a2a2e6cee50d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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