Please use dput() to give a reproducible example: I can make this work
on a data frame quite easily --
x <- data.frame(1:10, letters[1:10], rnorm(10))
str(x)
print(x)
x[sample(nrow(x), 5), ]
So it's not a problem with something being a data frame or having factors.
Michael
On Thu, Mar 8, 2012 a
Thanks, but it doesn't work either, it gives me the same message error.
It works just if my first sample is taken in this way:
mysample <- sample(1:nrow(MeanA), 20, replace=FALSE)
However, in this way it sample just the number of rows:
[1] 71 24 12 36 2 39 69 62 43 38 9 44 13 54 50 63 67 66 3
>
> Hi, thank you but it does work for vectors and matrix but not
dataframes, it
> gives me this message error:
>
> MeanA <- read.csv("MeanAmf.csv",header=T)
> mysample <- MeanA[sample(1:nrow(MeanA), 20, replace=FALSE),]
Well, maybe slight correction
mysample <- sample(1:nrow(MeanA), 20, repla
Hi
I have only faint idea what was you problem as there is no context in you
message but maybe
remainder<-MeanA[-mysample, ]
could work.
Regards
Petr
>
> Hi, thank you but it does work for vectors and matrix but not
dataframes, it
> gives me this message error:
>
> MeanA <- read.csv("MeanA
Hi sarah, it is not clear to me how to do that, can you show me please?
Imagine I have a situation like this:
MeanA <- read.csv("MeanAmf.csv",header=T)
mysample <- MeanA[sample(1:nrow(MeanA), 20, replace=FALSE),]
Then?
--
View this message in context:
http://r.789695.n4.nabble.com/Sampling-pr
Hi, thank you but it does work for vectors and matrix but not dataframes, it
gives me this message error:
MeanA <- read.csv("MeanAmf.csv",header=T)
mysample <- MeanA[sample(1:nrow(MeanA), 20, replace=FALSE),]
remainder<-MeanA[-mysample]
Error in `[.default`(MeanA, -mysample) : invalid subscript ty
On Mar 7, 2012, at 11:41 AM, Oritteropus wrote:
Hi,
I need to sample randomly my dataset for 1000 times. The sample need
to be
the 80%. I know how to do that, my problem is that not only I need
the 80%,
but I also need the corresponding 20% each time. Is there any way to
do
that?
Alterna
On Wed, Mar 07, 2012 at 08:41:35AM -0800, Oritteropus wrote:
> Hi,
> I need to sample randomly my dataset for 1000 times. The sample need to be
> the 80%. I know how to do that, my problem is that not only I need the 80%,
> but I also need the corresponding 20% each time. Is there any way to do
> t
You could make a vector containing the number of TRUE values that
makes up 80% of your data, and the number of FALSE values that makes
up 20% of your data. Use sample() to reorder it, then use it to divide
your dataset.
If you had provided a reproducible example, I could write you code.
Sarah
On
9 matches
Mail list logo