[R] Sampling

Robert W. Baer, Ph.D. rbaer at atsu.edu
Fri Oct 10 23:26:59 CEST 2008


How about:
 T2=rnorm(1000)
  temp=list(NULL)
  for(i in 1:5){temp[[i]]<-sample(T2,40,replace=F)};show(temp)

----- Original Message ----- 
From: "Rolf Turner" <r.turner at auckland.ac.nz>
To: "Alex99" <loyola9988 at yahoo.com>
Cc: <r-help at r-project.org>
Sent: Friday, October 10, 2008 3:36 PM
Subject: Re: [R] Sampling


>
> On 11/10/2008, at 7:38 AM, Alex99 wrote:
>
>>
>> Hi Guys,
>> I am in desperate need with sampling. I am suppose to sample from a 
>> dataset.
>> I use the following code:
>>
>>> for(i in 1:5){temp[i]<-sample(T2,40,replace=F)
>> + show(temp)}
>>
>> but all the samples are the same, but I want them to be different.any
>> suggestion?
>
> Yes.  Read the posting guide.
>
> (a) Your example is not reproducible.  What is T2?  How is temp
> initialized?
>
> (b) In the assignment temp[i] <- sample(T2,40,replace=FALSE)
> you are attempting to assign a vector of length 40 to an object
> of length 1; that can't possibly work, now, can it?  It should
> give you warning messages.
>
> (c) I really can't figure out how you're getting ``all the samples are
> the same''.  Things go wrong, but not that.
>
> Tell us what you *really* did.
>
> cheers,
>
> Rolf Turner
>
> ######################################################################
> Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list