[R-sig-Geo] basic question
Ashton Shortridge
ashton at msu.edu
Wed May 22 16:12:55 CEST 2013
Hi Kátia,
this isn't really a spatial question, but here goes with an answer.
Your solution lies in the help documentation for the sample function. At the
command prompt, type ?sample for one way to access help. The basic
command is this:
sample(x, size, replace = FALSE, prob = NULL)
For R beginners and experts alike, often the most helpful part of help is the
usage section at the bottom of the documentation. You can run the example
usage code at the command prompt to see what happens.
In your specific question, you can see that you simply do this:
x <- 1:12
sample(x, 5, replace=TRUE) # probably duplicates; what you want, right?
so for your example, this should work:
h<-dados[sample(1:357,20, replace=TRUE),]
Yours,
Ashton
On 05/22/13, Kátia Emidio, wrote:
> does anyone could help me with do a sample from dataframe, using
> replacement equal True? I am a very beginner at R.
>
> without replacement, my script works...
>
> h<-dados[sample(1:357,20),]# this is ok. from 357 rows, I take 20 ones,
> with all columms... How puts the replace=T ?
> thanks
> katia
-----
Ashton Shortridge
Associate Professor ashton at msu.edu
Dept of Geography http://www.msu.edu/~ashton
235 Geography Building ph (517) 432-3561
Michigan State University fx (517) 432-1671
More information about the R-sig-Geo
mailing list