[R] using sample

2011-12-07 Thread bevare
Hi, Can anyone help sort out the problem with the following script - I am a R newbie and I am self taught. obs.all = c() for(i in 1:386){ if (n.sim[i]0){ obs = (1:133429)[event.details[,2] == i] obs.all = c(obs.all, sample(obs[obs n.sim[i]], size = n.sim[i],

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

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

2010-07-22 Thread Jon BR
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 the vector is down in size to containing only one element, I run into the undesired behaviour acknowledged in the

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 jonsle...@gmail.com 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

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]) # length

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 had...@rice.edu 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 =

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) #

[R] Using sample to create Training and Test sets

2009-05-15 Thread 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 set using whats left over. Example code: acc - read.table(accOUT.txt, header=T, sep = ,, row.names=1) #select 400 random rows in data 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

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 set

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 distribution of

[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