I think the way to think about this might be to
draw a random sample of
numbers from the numbers of observations in the data (so say to draw a
random sample of numbers from the numbers 1-1000), and then once you have
your random sample of numbers to call out/subset the dataset with the
numbers from your sample:
my.sample<-sample(x=1:nrow(data), size=samp.size, replace=TRUE)
data.matrix<-data[my.sample,]
hope that helps.
-diane
On Sat, Feb 7, 2009 at 12:58 AM, John-Paul Ferguson <jpferg at mit.edu>wrote:
It's more the first step than the last--but
yes, you're right. Thanks!
--JP
On Fri, Feb 6, 2009 at 11:38 PM, Bernard L. Fraga <
bfraga at fas.harvard.edu> wrote:
> I think it's just that you're missing the last step, which is to
> associate the draw of "row numbers" with the data for each of those rows.
> Code like the following might be helpful:
>
> yoursample <- samplespace[thedraw,]
>
> I haven't checked this, but hopefully this is a start. Good luck!
>
> -Bernard
>
> -----------------------
> Bernard L. Fraga
> Ph.D. Student, Harvard University
> Government and Social Policy
> bfraga at
fas.harvard.edu
> -----------------------
>
> On Feb 6, 2009, at 11:13 PM, John-Paul Ferguson wrote:
>
> Hi Everyone,
>
> I decided to get an early start on the problem set. I have a question
> about the sample() command, if anyone has gone that far (this relates to
> 2.4).
>
> In question 2.4, we are told to "Randomly draw 100 datasets with 50
> observations each from the data loaded in part 2.2 with replacement...using
> sample()". I can't figure out how to get sample() to draw *rows*rather than
single
> *values*. That is, if I write
>
> samplespace <- matrix(c(y,x1,x2,x3),1000,4)
> thedraw <- sample(samplespace, 50, replace=TRUE)
>
> then I get fifty scalars rather than fifty rows from the matrix
> samplespace. Can anyone see what I'm getting wrong here? The help on
> sample() isn't actually much help; it too seems to assume that you'll be
> drawing numbers.
>
> I normally wouldn't post such a "basic" question, but I figure that I
> can't be the only person who's puzzling out R syntax this week!
>
> Best,
> John-Paul Ferguson
>
> PhD Candidate, Economic Sociology
> MIT Sloan School of Management
> 50 Memorial Drive, E52-533
> Cambridge, MA 02142
> 617.253.3940 (w)
> 617.549.8482 (c)
>
http://web.mit.edu/jpferg/www
> _______________________________________________
> gov2001-l mailing list
> gov2001-l at
lists.fas.harvard.edu
>
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l
>
>
>
> _______________________________________________
> gov2001-l mailing list
> gov2001-l at
lists.fas.harvard.edu
>
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l
>
>
_______________________________________________
gov2001-l mailing list
gov2001-l at
lists.fas.harvard.edu
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l
--
Diane Kuhn
PhD Candidate
Department of Government
Harvard University
dmkuhn at
_______________________________________________
gov2001-l mailing list
gov2001-l at