Skip to content
Prev 311464 / 398513 Next

Select a random subset of rows out of matrix

Hello,

It's not, in general, possible to fullfill the two constraints, to both 
select 80% of the rows and to select all x %in% sampled x. Maybe the 
following is a way close enough.

set.seed(244)
s <- sample(unique(dat$x), length(unique(dat$x))*0.8, prob = table(dat$x))
dat[dat$x %in% s,]


Hope this helps,

Rui Barradas
Em 21-11-2012 13:25, arun escreveu: