Skip to content
Back to formatted view

Raw Message

Message-ID: <20111117113659.63160@gmx.net>
Date: 2011-11-17T11:36:59Z
From: Johannes Radinger
Subject: How to resample one per group

Hello,

I have got a dataframe which looks like:

y <- c(1,5,6,2,5,10) # response
x <- c(2,12,8,1,16,17) # predictor
group <- factor(c(1,2,2,3,4,4)) # group
df <- data.frame(y,x,group)

Now I'd like to resample that dataset. 
I want to get dataset (row)
per group. So per total sample I get 4 rows
into a new data frame. How can I do that?
Is there any simple approach using an existing
package.

I looked at function strata() from package sampling.
I don't if that is the function for that or
if there is a simpler approach with sample().

What I unsuccessfully tried so far:

library(sampling)
strata(data=df,group,size=(rep(1,nlevels(group))))

Maybe you can help me to do this resampling...

Thank you,
Johannes
--