[R] Random sample from a data frame where ID column values don't match the values in an ID column in a second data frame

inkhorn matt.dubins at gmail.com
Fri Mar 30 15:05:44 CEST 2012


Okay thanks to your help I figured it out and stuck the code in a function:

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)
}

Cheers,
Matt Dubins

--
View this message in context: http://r.789695.n4.nabble.com/Random-sample-from-a-data-frame-where-ID-column-values-don-t-match-the-values-in-an-ID-column-in-a-se-tp4516448p4518972.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list