[R] Problem with sample function

David Winsemius dwinsemius at comcast.net
Fri Jun 8 18:45:36 CEST 2012


On Jun 8, 2012, at 12:33 PM, Guido Leoni wrote:

> Dear list
> Is there a way  to extract a random sample without duplicated row  
> from a
> dataframe ?.
> a=c(1,2,3,1,1,1,2,1)
> b=c(1,2,3,1,2,1,2,1)
> c=c(1,1,1,1,1,1,1,1)
> d=c(1,2,3,1,1,1,2,1)
> prov<-data.frame(a,b,c,d)
> prov2<-prov[sample(1:nrow(prov),5,replace=T),]
> prov2
>    a b c d
> 3   3 3 1 3
> 6   1 1 1 1
> 3.1 3 3 1 3
> 5   1 2 1 1
> 8   1 1 1 1
>
> I tryed  the above code but as you can see sample function includes  
> also
> duplicates.
> thank you for any tip

Why would you use replace=T if you didn't want duplicates???

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list