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],
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
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
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
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
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 =
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)
#
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
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
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
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
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
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
13 matches
Mail list logo