Re: [R] random sampling inside a dataset

2012-10-04 Thread Marianna Chimienti
Hi, I guess it is because when you have the FALSE option the sample function take off the number from the whole population so your data_frame becomes different in length. If you try with the option TRUE it works (of course) but then you have the possibility that you sample the same row twice. Hope

Re: [R] random sampling inside a dataset

2012-10-04 Thread Duncan Murdoch
On 12-10-04 6:06 AM, Gian Maria Niccolò Benucci wrote: Hi again to everybody, I incountered the following error when I try to make a sample inside a dataset. My code is: data_ostrya <- sample(ostrya,200, replace=F) Error in `[.data.frame`(x, .Internal(sample(length(x), size, replace, : ca

Re: [R] random sampling inside a dataset

2012-10-04 Thread Rui Barradas
Hello, If the dataset 'data_ostrya' is kept in a data.frame, then length(data_ostrya) is equal to the number of columns, not the number of rows. This is because a data.frame is a special type of list and length(some_list) is the number of its elements (obvious). if you want to sample rows, try

Re: [R] random sampling inside a dataset

2012-10-04 Thread Gian Maria Niccolò Benucci
Hi again to everybody, I incountered the following error when I try to make a sample inside a dataset. My code is: > data_ostrya <- sample(ostrya,200, replace=F) Error in `[.data.frame`(x, .Internal(sample(length(x), size, replace, : cannot take a sample larger than the population when 'replac

Re: [R] random sampling inside a dataset

2012-09-13 Thread Duncan Murdoch
On 12-09-13 7:18 AM, Gian Maria Niccolò Benucci wrote: Thank you very much for your help, I was wondering if is possible to sample randomly specifying to select in a particular group of data inside the matrix, for example only within the whole samples collected in 2011 I would randomly choose 20

Re: [R] random sampling inside a dataset

2012-09-13 Thread Gian Maria Niccolò Benucci
Thank you very much for your help, I was wondering if is possible to sample randomly specifying to select in a particular group of data inside the matrix, for example only within the whole samples collected in 2011 I would randomly choose 20 random samples... Thanks a again, Gian On 13 Septemb

Re: [R] random sampling inside a dataset

2012-09-13 Thread Berend Hasselman
On 13-09-2012, at 10:42, Gian Maria Niccolò Benucci wrote: > Hi all, > > I am wondering if do exist a function in R that allow me to sample or > choose randomly the rows (i.e., samples) inside a given matrix. Use sample. Like this for example A <- matrix(runif(8*4), nrow=8) A select.row <- sa