Skip to content

Instantly share code, notes, and snippets.

@inkhorn
Created March 30, 2012 13:08
Show Gist options
  • Save inkhorn/2251415 to your computer and use it in GitHub Desktop.
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 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