You might create a matrix, 100 by n:
mat <- matrix (runif (100 * n), nrow = 100)
then apply a function to each row to compute the sum of those numbers under
.01:
apply (mat, 1, function(x) sum (x < .01))
I hope this helps,
Sam Buttrey
buttrey@nps.navy.mil
-
Daikwon Han wrote:
> Dear all,
>
> Can anyone help me to create 100 numbers from the below program ?
> I'm doing simulation to pick up random numbers and calculate the change of
> total values over time. The first thing I did is to pick up the 1000
> numbers between 0 and 1 under the uniform distribution and add all the
> values less than .01 as follows.
>
> x<-runif(1000,0,1)
> x<-sum(as.numeric(x<.01))
>
> Let's say, I got 9 as x value at the first trial, then I want to repeat
> it 100 times so that I can get 100 different numbers.
> I've tried "for(i in 1:100)" and "while(i<101)" loop, but it doesn't work
> well. I also tried matrix, append command, I only got the same number
> repeated 100 times, probably the first one(same 100 numbers in the table).
>
> My question is how to make a loop to keep each value at each trial(should
> be 100 different numbers at 100 trials). Any help would be appreciated.
> Thank you.
>
> -----------------------------
> Daikwon Han, Ph.D Candidate
> Department of Geography
> SUNY at Buffalo
> Buffalo, NY 14226
> -----------------------------
>
>
> ---------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu. To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message: unsubscribe s-news
--
Dr. M. Henry H. Stevens
Postdoctoral Associate
Department of Ecology, Evolution, & Natural Resources
14 College Farm Road
Cook College, Rutgers University
New Brunswick, NJ 08901-8551
email: hstevens@rci.rutgers.edu
phone: 732-932-9631
fax: 732-932-8746
---------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
|