Here's one way to do what I think you want:
> set.seed(1)
> # Generate a sample data frame with one column 'x'
> d <- data.frame(x=sample(c(10:14,100),50,rep=T))
> # Create a vector with the sum of 1000 samples of size
> # 10 (with replacement)
> res <- sapply(1:1000, function(i) sum(sample(d$x, 10, rep=T)))
> hist(res)
>
Khan, Sohail wrote:
Dear List
I want to write a "little" piece of code which would :
-- take sample of 10 values (randomly) from a data.frame column
-- sum these values
-- put the values in a vector
-- repeat 1000 times
I would later draw a histogram of this generated vector.
Thanks in advance for any advice/suggestions.
Sohail Khan
Scientific Programmer
COLD SPRING HARBOR LABORATORY
Genome Research Center
500 Sunnyside Boulevard
Woodbury, NY 11797
(516)422-4076
--------------------------------------------------------------------
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
|