s-news
[Top] [All Lists]

Re: Generating a vector dynamically

To: "Khan, Sohail" <khan@cshl.edu>
Subject: Re: Generating a vector dynamically
From: Tony Plate <tplate@blackmesacapital.com>
Date: Thu, 20 Apr 2006 18:13:58 -0600
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <C8696843AE995F4EA4CDC3E2B83482A901879009@mailbox02.cshl.edu>
References: <C8696843AE995F4EA4CDC3E2B83482A901879009@mailbox02.cshl.edu>
User-agent: Mozilla Thunderbird 1.0.5 (Windows/20050711)
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



<Prev in Thread] Current Thread [Next in Thread>