s-news
[Top] [All Lists]

Re: random samples

To: "Richard Pugh" <rpugh@mango-solutions.com>, <s-news@lists.biostat.wustl.edu>
Subject: Re: random samples
From: "Roberts, J. Kyle" <jkrobert@bcm.tmc.edu>
Date: Sat, 22 Apr 2006 15:36:51 -0500
References: <200604221032.k3MAWXhf004753@dignan.corp.bcm.tmc.edu>
Thread-index: AcZlhDjKLDsJ931OQxa0ZCNpj1dmSwAc8IIAABThOA4=
Thread-topic: [S] random samples

Rich (and others),

Sort of.  This is more what I want.

x<-1

for (i in seq(1,10,length=30)){

     x<-append(x, sort(rnorm(30, 50, i)))

}

The problem is that the only way I can figure out how to do it is by first starting with "x" having some value in it so that I can use the "append" statement.  I then have to delete the first "row" before using the data.  I decided to use the "for" statement because I also have a command that does the following to apply a "grouping variable" for each set of random numbers:

y<-1

for (i in 1:30){

    y<-append(y, rep(i, 30))

}

I have the same problem here, though.  Any ideas?

Thanks,

Kyle



From: Richard Pugh [mailto:rpugh@mango-solutions.com]
Sent: Sat 4/22/2006 5:32 AM
To: Roberts, J. Kyle
Subject: RE: [S] random samples

Hi Kyle

 

Is this what you want?

 

> sapply(seq(1, 10, length=30), rnorm, n=1, mean=0)

 [1]  -0.81725561  -3.08122241   1.06784505  -0.08974292   1.67823407  -4.70454218

 [7]   0.30273341   0.99100837  -4.92922917  -1.96928729   0.76185292  10.73067244

[13]   3.09920886   1.87420172  -0.78714101   9.79541771  -3.35487967   2.44693247

[19]  10.70601907   1.68186712   5.70838928   8.46980920  -0.97129270  -6.99468471

[25] -13.38216398   0.12119373  -3.14704500   0.45912028  -0.43485937  -5.46393800

 

Rich.

 


From: s-news-owner@lists.biostat.wustl.edu [mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Roberts, J. Kyle
Sent: 21 April 2006 21:50
To: s-news@lists.biostat.wustl.edu
Subject: [S] random samples

 

Dear All,

 

I want to create 30 random samples of 30 scores all in the same vector (all with the same mean).  The twist is that I want to be able to specify a different SD for each sample such that seq(1, 10, length=30).  Before I put the random samples together, however, I want them to appear in ascending order (within each group).  I can easily do this the long way, but I wonder if someone can figure out an easy way.

 

Thanks,

Kyle

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