On 06/06/14 15:39, Rodrigues wrote:
> Dear R users,
>
>
> I’m trying to build a function to select random samples idf’s from a
> database.
> So, my data frame had 2 columns and 575 rows. Follow bellow an example of my
> database
> Idf1	casod
> 12	1
> 14	1
> 15	1
> 16	1
> 17	3
> 18	3
> 19	3
> 21	3
> 25	1
> 24	1
> 26	1
> 28	1
> 29	3
> 32	3
> 33	3
> 35	1
> 36	3
> 37	1
> 48	3
>
> So my function is
>
> blinding=function(sample){
>    sort=sample(idf1,10,replace=F)
>    return(sort2)
> }
Does this work? It looks like you're passing a function to the function! 
Also, you're not returning something that has been calculated. In 
practice, you might as well just use sample(idf1,10,replace=F).

> It is pretty simple and I would like to add one more step in my choice. I
> would like to link my choice to casod stats. Thus if casod==3 sample would
> be random idfs could not be an idf with casod=1. Does someone can help me?
If I understand you, you only want to sample within casod==3. So this 
will work:

sample(idf1[casod==3],10,replace=F)

Or, if you need a wrapper function, this should work:

blinding=function(which.casod, df, N=10) 
sample(df$idf1[df$casod==which.casod], N, replace=F)

e.g. SampledData=sapply(unique(Data$casod), blinding, df=Data)
will sample for each value of casod

Bob

-- 

Bob O'Hara

Biodiversity and Climate Research Centre
Senckenberganlage 25
D-60325 Frankfurt am Main,
Germany

Tel: +49 69 7542 1863
Mobile: +49 1515 888 5440
WWW:   http://www.bik-f.de/root/index.php?page_id=219
Blog: http://blogs.nature.com/boboh
Journal of Negative Results - EEB: www.jnr-eeb.org


	[[alternative HTML version deleted]]

