[R] Using sample() with a data frame ?

2008-08-25 Thread Martin Hvidberg
I have a data frame (daf1), that holds +8 records, and 10 variables (i.e. 10 columns and some 8 rows) length(daf1) [1] 10 length(daf1[,1]) [1] 83805 I would like to sample() e.g. 1 records from this. I use: daf2 - sample(daf1, 1000, replace = FALSE, prob = NULL) Error in

Re: [R] Using sample() with a data frame ?

2008-08-25 Thread baptiste auguie
Hi, I find convenient to use a custom function for this: sample.df - function (df, N = 1000, ...) { df[sample(nrow(df), N, ...), ] } sample.df(daf1,1000) Hope this helps, baptiste On 25 Aug 2008, at 12:31, Martin Hvidberg wrote: I have a data frame (daf1), that holds +8