Sorry, I should say something like this (I am doing stuff in a few languages, messed up the syntax in my last email) ….



randomSample <- function(df,fraction=0.5){
  fraction = min(max(0,fraction),1) #Just to check
  nrows    = nrow(df)
  number   = max(1,floor(fraction*nrows))
  rowIds = sample(1:nrows,number)
  df[rowIds,] #
}



--
Nicholas Hamilton
School of Materials Science and Engineering
University of New South Wales (Australia)
—
www.ggtern.com





On 6 Jun 2014, at 2:49 pm, Nicholas Hamilton <n.hamilton@student.unsw.edu.au> wrote:

> A function, something like this?
> 
> 
> randomSample(df,fraction=0.5){
>   fraction = min(max(0,fraction),1) #Just to check
>   nrows    = nrow(df)
>   number   = max(1,floor(fraction*nrows))
>   rowIds = sample(1:nrows,number)
>   df[rowIds,] 
> }
> 
> 
> --
> Nicholas Hamilton
> School of Materials Science and Engineering
> University of New South Wales (Australia)
> �
> www.ggtern.com
> 
> 
> 
> 
> 
> On 6 Jun 2014, at 2:39 pm, Rodrigues <rodriguesmsb@gmail.com> 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)
> > }
> > 
> > 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?
> > 
> > 
> > 
> > 
> > --
> > View this message in context: http://r-sig-ecology.471788.n2.nabble.com/Help-with-a-function-tp7578931.html
> > Sent from the r-sig-ecology mailing list archive at Nabble.com.
> > 
> > _______________________________________________
> > R-sig-ecology mailing list
> > R-sig-ecology@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
> 
> 
>         [[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


	[[alternative HTML version deleted]]

