Emma,
If you haven't spent much time on the r-help forums, please do read the
posting guide.
You need to provide reproducible examples for us to help you.
We don't know anything about your data...
what is event.details, (if you can't provide the data often ?str will do)
since I don't know what
And, surely, regardless of R version:
resamp <- function(x,...){if(length(x)==1) x else sample(x,...)}
resamp((1:10),10)
# [1] 8 2 10 6 5 4 3 7 9 1
resamp((1:10),1)
# [1] 7
resamp((1:10),1)
# [1] 4
resamp((1:10),1)
# [1] 10
resamp(10,1)
# [1] 10
resamp(10,1)
# [
I see.. Thanks!
On Thu, Jul 22, 2010 at 4:39 PM, Hadley Wickham wrote:
> Did you look at the examples in sample?
>
> # sample()'s surprise -- example
> x <- 1:10
> sample(x[x > 8]) # length 2
> sample(x[x > 9]) # oops -- length 10!
> sample(x[x > 10]) # length 0
>
> ## For R >= 2.11.0
Did you look at the examples in sample?
# sample()'s surprise -- example
x <- 1:10
sample(x[x > 8]) # length 2
sample(x[x > 9]) # oops -- length 10!
sample(x[x > 10]) # length 0
## For R >= 2.11.0 only
resample <- function(x, ...) x[sample.int(length(x), ...)]
resample(x[x > 8]) #
Try this:
x <- 10
sample(x, 1, prob = c(rep(0, x - 1), 1))
On Thu, Jul 22, 2010 at 5:31 PM, Jon BR wrote:
> Hi All,
>I'm trying to use the "sample" function within a loop where the
> vector being sampled from (the first argument in the function) will
> vary in length and composition. When
>> Forgive the newbie question, I want to select random rows from my
>> data.frame to create a test set (which I can do) but then I want to
>> create a training set using whats left over.
>>
The caret package has a function, createDataPartition, that does the
split taking into account the distribu
Here's one possibility:
idx <- sample(nrow(acc))
training <- acc[idx[1:400], ]
testset <- acc[-idx[1:400], ]
Andy
From: Chris Arthur
>
> Forgive the newbie question, I want to select random rows from my
> data.frame to create a test set (which I can do) but then I want to
> create a training
Note that the single split sample technique is not competitive with
other approaches unless the sample size exceeds around 20,000.
Frank
Chris Arthur wrote:
Forgive the newbie question, I want to select random rows from my
data.frame to create a test set (which I can do) but then I want to
c
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 record
9 matches
Mail list logo