[R] repeat a function

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Thu Sep 30 02:57:20 CEST 2010


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Michael Bedward
> Sent: Wednesday, September 29, 2010 5:34 PM
> To: Michael Larkin; Rhelp
> Subject: Re: [R] repeat a function
> 
> On 30 September 2010 02:48, Michael Larkin <mlarkin at rsmas.miami.edu>
> wrote:
> > >
> > > testdat <- replicate( 50, growth[ sample(nrow(growth), 8, rep=TRUE)
> ] )
> >
> > I can't seem to get it to work.  I keep getting the error message of
> > "undefined columns selected"
> >
> > Any advice?
> 

Michael,

As has been pointed out, you seem to be trying to reinvent the wheel.  But to answer your question, you need a comma just before the final square bracket. Then you need to set the simplify=FALSE parameter for the replicate function.  So something like this

testdat <- replicate( 50, growth[sample(nrow(growth), 8, rep=TRUE),], simplify=FALSE)


Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204




More information about the R-help mailing list