Created
March 30, 2012 13:08
-
-
Save inkhorn/2251415 to your computer and use it in GitHub Desktop.
Function to Sample Rows from a Data Frame Excluding the ID Values from Another Sample Data Frame
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
# This function assumes that you're going to input ID1.name and ID2.name as strings. | |
df.sample.exIDs = function(main.df, sample1.df, n, ID1.name, ID2.name) { | |
main.ID1.notin.ID2 = main.df[!main.df[,ID1.name] %in% sample1.df[,ID2.name],] | |
sample2.df = main.ID1.notin.ID2[sample(nrow(main.ID1.notin.ID2), size=n),] | |
return(sample2.df) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment