Hi, take the following example and proceed accordingly. Name=c("Miller","Miller","Miller","Miller","Smith","Smith","Smith","Smith") X=rnorm(8) Year=rep(2000:2003,2)
d=data.frame(Name,X,Year) #Row indices rows=1:dim(d)[1] #Which Name occupies which rows? #"Name" would be your "file" w=function(x){which(Name%in%unique(x))} samplefrom=tapply(Name,Name,w) #Sample one row index for each Name and #give the data frame d for these row indices f=function(x){sample(x,1)} d[unlist(lapply(samplefrom,f)),] HTH, Daniel -- View this message in context: http://r.789695.n4.nabble.com/sampling-one-random-frame-from-each-unique-trial-tp2270396p2270465.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.