Skip to content
Prev 163634 / 398506 Next

sampling from data.frame

On Wed, 3 Dec 2008, axionator wrote:

            
Something like this:

cl.samps <- sample( split( df, df$cluster ), n.samps, repl=TRUE )

do.call( rbind, cl.samps )

If you need to identify the samples from which the rows came (versus just 
the originating clusters):

cl.samps2 <- lapply( seq(along=cl.samps),
 	function(x) cbind( cl.samps[[ x ]], new.cluster = x ) )

do.call( rbind, cl.samps2 )

HTH,

Chuck
Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901