Re: [R] Sampling problems

2012-03-08 Thread R. Michael Weylandt
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

Re: [R] Sampling problems

2012-03-08 Thread Oritteropus
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

Re: [R] Sampling problems

2012-03-08 Thread Petr PIKAL
> > 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

Re: [R] Sampling problems

2012-03-08 Thread Petr PIKAL
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

Re: [R] Sampling problems

2012-03-08 Thread Oritteropus
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

Re: [R] Sampling problems

2012-03-08 Thread Oritteropus
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

Re: [R] Sampling problems

2012-03-07 Thread David Winsemius
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

Re: [R] Sampling problems

2012-03-07 Thread Petr Savicky
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

Re: [R] Sampling problems

2012-03-07 Thread Sarah Goslee
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