[R] Repeated analysis over groups / Splitting by group variable

2010-07-15 Thread Ralf B
I am performing some analysis over a large data frame and would like to conduct repeated analysis over grouped-up subsets. How can I do that? Here some example code for clarification: require(flexmix) # for Kullback-Leibler divergence n - 23 groups - c(1,2,3) mydata - data.frame(

Re: [R] Repeated analysis over groups / Splitting by group variable

2010-07-15 Thread Phil Spector
Ralf - If you want to use by(), I think it should look like this: by(dataOnly,dataOnly[,3],function(x)KLdiv(as.matrix(x))) But you might find the following more useful: lapply(split(as.data.frame(dataOnly),dataOnly[,3]), function(x)KLdiv(as.matrix(x))) since it returns its

Re: [R] Repeated analysis over groups / Splitting by group variable

2010-07-15 Thread Peter Ehlers
I would change that first dataOnly in by(...) or lapply(...) to dataOnly[,-3]. In fact, if the dataframe mydata is suitably subset, then, because of the as.matrix() in function(x), both the by() and lapply() methods will work fine with mydata. -Peter Ehlers On 2010-07-15 15:42, Phil Spector