Re: [R] using sample

2011-12-07 Thread Justin Haynes
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

Re: [R] using "sample()" for a vector of length 1

2010-07-22 Thread Ted Harding
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) # [

Re: [R] using "sample()" for a vector of length 1

2010-07-22 Thread Jonathan
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

Re: [R] using "sample()" for a vector of length 1

2010-07-22 Thread Hadley Wickham
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]) #

Re: [R] using "sample()" for a vector of length 1

2010-07-22 Thread Henrique Dallazuanna
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

Re: [R] Using sample to create Training and Test sets

2009-05-15 Thread Max Kuhn
>> 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

Re: [R] Using sample to create Training and Test sets

2009-05-15 Thread Liaw, Andy
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

Re: [R] Using sample to create Training and Test sets

2009-05-15 Thread Frank E Harrell Jr
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

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 record