Re: [R] Coin Toss Simulation

2010-10-13 Thread Shiv

Erik- thank you very much. The rbinom worked.  

Thanks !
GR






From: Erik Iverson-3 [via R] 

Sent: Wed, October 13, 2010 2:24:18 PM
Subject: Re: Coin Toss Simulation



Shiv wrote: 

> I am trying a simple toin coss simulation, of say 200 coin tosses. The idea 
> is to have a data frame like so: 
> Experiment#Number_Of_Heads 
>  1   104 
>  296 
>  3101 
> 
> So I do: 
> 
>  d <-data.frame(exp_num=c(1,2,3));  /* Just 3 experiments to begin with */ 
>  d$head_ct <-sum(sample(0:1,200,repl=TRUE)); 
/* */ is not a valid comment in R, and you don't need ';' either :) 

Just try evaluating the right hand side so that the R interpreter 
prints the result.  This is just calling sample once, and therefore 
you only get one number, 85 in your case. 


>  d; 
>   exp_numhead_ct 
> 1   185 
> 2   285 
> 3   385 /* the same scalar value is 
> applied to all the rows */ 
> 
> So I tried using "within", and "for", and making the "sum(   " as a 
> function, and I end up with the same...I get the same constant value.  But 
> what I want of course is different "samples" 
Look at ?replicate or just use ?rbinom directly 

d <-data.frame(exp_num = 1:3) 
d$head_ct <- rbinom(nrow(d), 200, prob = 0.5) 



> 
> 
> 

__ 
[hidden email] 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. 



 
View message @ 
http://r.789695.n4.nabble.com/Coin-Toss-Simulation-tp2994088p2994186.html 

To unsubscribe from Coin Toss Simulation, click here. 



  
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Coin-Toss-Simulation-tp2994088p2994284.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

__
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.


[R] Coin Toss Simulation

2010-10-13 Thread Shiv

I am trying a simple toin coss simulation, of say 200 coin tosses. The idea
is to have a data frame like so:
Experiment#Number_Of_Heads
 1   104
 296
 3101

So I do:

 d <-data.frame(exp_num=c(1,2,3));  /* Just 3 experiments to begin with */
 d$head_ct <-sum(sample(0:1,200,repl=TRUE));
 d;
  exp_numhead_ct
1   185
2   285
3   385 /* the same scalar value is
applied to all the rows */

So I tried using "within", and "for", and making the "sum(   " as a
function, and I end up with the same...I get the same constant value.  But
what I want of course is different "samples"



-- 
View this message in context: 
http://r.789695.n4.nabble.com/Coin-Toss-Simulation-tp2994088p2994088.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.