Re: [R] multivariate version of aggregate

2013-06-28 Thread arun
- From: Jannis To: Greg Snow <538...@gmail.com> Cc: r-help Sent: Friday, June 28, 2013 4:31 AM Subject: Re: [R] multivariate version of aggregate Yes, I had a look at that function. From the documentation, however, it did not get clear to me how to split the dataframe into subsets of rows

Re: [R] multivariate version of aggregate

2013-06-28 Thread Jannis
Thanks a lot to everybody who responded! My solution now looks similar to Ruis and Davids suggestions. Jannis On 28.06.2013 11:00, Rui Barradas wrote: Hello, You can solve your problem using only base R, with no need for an external package. The two instrucitons below are two ways of doing

Re: [R] multivariate version of aggregate

2013-06-28 Thread Rui Barradas
Hello, You can solve your problem using only base R, with no need for an external package. The two instrucitons below are two ways of doing the same. sapply(split(testframe, indices), function(x) cor(x[, 1], x[, 2])) as.vector(by(testframe, indices, function(x) cor(x[, 1], x[, 2]))) Hope

Re: [R] multivariate version of aggregate

2013-06-28 Thread Jannis
Yes, I had a look at that function. From the documentation, however, it did not get clear to me how to split the dataframe into subsets of rows based on an index argument. Like: testframe <- data.frame(a=rnorm(100), b = rnorm(100)) indices <- rep(c(1,2), each = 50) results <- ddply(.dat

Re: [R] multivariate version of aggregate

2013-06-27 Thread arun
7; Cc: Sent: Thursday, June 27, 2013 3:22 PM Subject: Re: [R] multivariate version of aggregate You can pass a matrix to by() > set.seed(42) > dat <- data.frame(x=runif(50)*20, y=runif(50)*20, g=rep(LETTERS[1:2], each=25)) > as.vector(by(dat[,1:2], dat$g, function(x) cor(x)

Re: [R] multivariate version of aggregate

2013-06-27 Thread Rui Barradas
ailto:r-help-boun...@r-project.org] On Behalf Of Jannis Sent: Thursday, June 27, 2013 12:27 PM To: r-help Subject: [R] multivariate version of aggregate Dear List members, i am seeking a multivariate version of aggregate. I want to compute, fro example the correlation between subsets of two vect

Re: [R] multivariate version of aggregate

2013-06-27 Thread Greg Snow
Look at the plyr package, probably the ddply function in that package. You can write your own function to do whatever you want on the pieces of the split apart object. Correlation between a specified pair of columns would be simple. On Thu, Jun 27, 2013 at 11:26 AM, Jannis wrote: > Dear List

Re: [R] multivariate version of aggregate

2013-06-27 Thread David Carlson
Professor of Anthropology Texas A&M University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jannis Sent: Thursday, June 27, 2013 12:27 PM To: r-help Subject: [R] multivariate version of aggregate D

[R] multivariate version of aggregate

2013-06-27 Thread Jannis
Dear List members, i am seeking a multivariate version of aggregate. I want to compute, fro example the correlation between subsets of two vectors. In aggregate, i can only supply one vector with indices for subsets. Is there ready function for this or do i need to program my own? Cheers