RE: [R] constrained sample

About this list Date view Thread view Subject view Author view Attachment view

From: Adaikalavan Ramasamy (ramasamy@cancer.org.uk)
Date: Fri 07 May 2004 - 04:22:01 EST


Message-id: <1083867721.4774.66.camel@vpn202001.lif.icnet.uk>

Possible something like this ?

> grp <- factor(rep(c("odd", "even"), 3)); val <- c(1,2,3,4,5,6)
> data.frame(grp, val)
   grp val
1 odd 1
2 even 2
3 odd 3
4 even 4
5 odd 5
6 even 6
> ( newval.list <- tapply(val, grp, sample) )
$even
[1] 6 4 2

$odd
[1] 3 1 5

> for(i in 1:length(newval.list)){
       val[ grp == names(newval.list)[i] ] <- newval.list[[i]]
  }
> data.frame(grp, val)
   grp val
1 odd 3
2 even 6
3 odd 1
4 even 4
5 odd 5
6 even 2

On Thu, 2004-05-06 at 19:00, Lutz Prechelt wrote:
> I'm afraid I do not understand what you need.
> What is sampled from where and what do you need to keep constant?
> And what is the relationship between the 'column' and the 'factor column'?
>
> Maybe you can provide a complete example and counterexample?
>
> Lutz
>
> > Is there an way to do a randomization (with sample) on a
> > column and that
> > maintain fixed the occurrence totals (i.e, numbers different
> > of zeros) on a factor column ?
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:08 EST